kredis 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kredis might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6a806a43280483f33a61cb2133b869d7742251eb7df3ccfcfe18c4bc5274873
4
- data.tar.gz: 1c255fa02c7172090724ee01b5f72ec5540b4e38c43505135bd123c2ab6a1c79
3
+ metadata.gz: b8c81a934c4d3b042045d49c96450e86c681529411fe5de467698d213f66bf21
4
+ data.tar.gz: b5d81f606b35fa29ebccd67940c4fd8d6f01c59d5957b0f3fb5aabf06c0f3896
5
5
  SHA512:
6
- metadata.gz: 270f4fda9ed70fb489e9b54431ae01118f2f25fcb6632a8eb83abb50e4ff0871729a4282989c75801bd6f0c7520f72d51923b6980c46089f0f27a3d8145a2a6e
7
- data.tar.gz: d1d5cc05fbe9091db57a20ad138e08cf1ee60d00765ebf69222cf53f9c153ce0a260496d0dd406c807ef1b6b51164ab365487c72e9299ca703d776add411c564
6
+ metadata.gz: 8dff036d7c5dfecb9e755d991419622cc2456a7eb4f79ea7a1a317156fc5ba87525b339f92726a19062c43716c23dce707ab1ec80253852dc79fed7a48cfade3
7
+ data.tar.gz: 64928a2e0d7c9ada0a51515dc8405339f053b5579f0cd57f109a52a38e23461a9be164db72c5fbb0eb0af8ff8fee3fb813e21c468b0d3e90c4a6a75747d7b777
@@ -25,6 +25,22 @@ module Kredis::Attributes
25
25
  end
26
26
  end
27
27
  end
28
+
29
+ def kredis_flag(name, config: :shared)
30
+ ivar_symbol = :"@#{name}_kredis_flag"
31
+
32
+ define_method(name) do
33
+ if instance_variable_defined?(ivar_symbol)
34
+ instance_variable_get(ivar_symbol)
35
+ else
36
+ instance_variable_set(ivar_symbol, Kredis.flag(kredis_key_for_attribute(name), config: config))
37
+ end
38
+ end
39
+
40
+ define_method("#{name}?") do
41
+ instance_variable_defined?(ivar_symbol) && instance_variable_get(ivar_symbol).marked?
42
+ end
43
+ end
28
44
  end
29
45
 
30
46
  private
@@ -15,6 +15,10 @@ module Kredis::Types
15
15
  Counter.new configured_for(config), namespaced_key(key), expires_in: expires_in
16
16
  end
17
17
 
18
+ def flag(key, config: :shared)
19
+ Flag.new configured_for(config), namespaced_key(key)
20
+ end
21
+
18
22
  def mutex(key, expires_in: nil, config: :shared)
19
23
  Mutex.new configured_for(config), namespaced_key(key), expires_in: expires_in
20
24
  end
@@ -24,4 +28,5 @@ require "kredis/proxy"
24
28
  require "kredis/types/list"
25
29
  require "kredis/types/unique_list"
26
30
  require "kredis/types/counter"
31
+ require "kredis/types/flag"
27
32
  require "kredis/types/mutex"
@@ -0,0 +1,13 @@
1
+ class Kredis::Types::Flag < Kredis::Proxy
2
+ def mark
3
+ set 1
4
+ end
5
+
6
+ def marked?
7
+ exists?
8
+ end
9
+
10
+ def remove
11
+ del
12
+ end
13
+ end
@@ -8,10 +8,10 @@ class Kredis::Types::List < Kredis::Proxy
8
8
  end
9
9
 
10
10
  def prepend(elements)
11
- lpush elements
11
+ lpush elements if Array(elements).any?
12
12
  end
13
13
 
14
14
  def append(elements)
15
- rpush elements
15
+ rpush elements if Array(elements).any?
16
16
  end
17
17
  end
@@ -10,7 +10,7 @@ class Kredis::Types::UniqueList < Kredis::Types::List
10
10
  remove elements
11
11
  super
12
12
  ltrim 0, (@limit - 1) if @limit
13
- end
13
+ end if Array(elements).any?
14
14
  end
15
15
 
16
16
  def append(elements)
@@ -18,6 +18,6 @@ class Kredis::Types::UniqueList < Kredis::Types::List
18
18
  remove elements
19
19
  super
20
20
  ltrim (@limit - 1), -1 if @limit
21
- end
21
+ end if Array(elements).any?
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module Kredis
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kredis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen
@@ -55,6 +55,7 @@ files:
55
55
  - lib/kredis/railtie.rb
56
56
  - lib/kredis/types.rb
57
57
  - lib/kredis/types/counter.rb
58
+ - lib/kredis/types/flag.rb
58
59
  - lib/kredis/types/list.rb
59
60
  - lib/kredis/types/mutex.rb
60
61
  - lib/kredis/types/unique_list.rb