key_value 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/key_value.gemspec +1 -1
- data/lib/key_value.rb +5 -2
- data/spec/key_value_spec.rb +9 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/key_value.gemspec
CHANGED
data/lib/key_value.rb
CHANGED
@@ -9,7 +9,6 @@ class KeyValue < ActiveRecord::Base
|
|
9
9
|
def self.get(key)
|
10
10
|
KeyValue.find_by_key(key).try(:value)
|
11
11
|
end
|
12
|
-
alias_method :get, :[]
|
13
12
|
|
14
13
|
def self.set(key, value)
|
15
14
|
if value
|
@@ -20,7 +19,11 @@ class KeyValue < ActiveRecord::Base
|
|
20
19
|
KeyValue.delete_all(:key => key)
|
21
20
|
end
|
22
21
|
end
|
23
|
-
|
22
|
+
|
23
|
+
class << self
|
24
|
+
alias_method :[], :get
|
25
|
+
alias_method :[]=, :set
|
26
|
+
end
|
24
27
|
|
25
28
|
def self.del(key)
|
26
29
|
set(key, nil)
|
data/spec/key_value_spec.rb
CHANGED
@@ -13,6 +13,10 @@ describe KeyValue do
|
|
13
13
|
KeyValue.get('xxx').should == nil
|
14
14
|
end
|
15
15
|
|
16
|
+
it "can get empty via []" do
|
17
|
+
KeyValue['xxx'].should == nil
|
18
|
+
end
|
19
|
+
|
16
20
|
it "can set & get" do
|
17
21
|
KeyValue.set('xxx', 1)
|
18
22
|
KeyValue.get('xxx').should == 1
|
@@ -40,4 +44,9 @@ describe KeyValue do
|
|
40
44
|
}.should change{KeyValue.count}.by(-1)
|
41
45
|
KeyValue.get('xxx').should == nil
|
42
46
|
end
|
47
|
+
|
48
|
+
it "can set empty via []=" do
|
49
|
+
KeyValue['xxx'] = 1
|
50
|
+
KeyValue['xxx'].should == 1
|
51
|
+
end
|
43
52
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: key_value
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roman Heinrich
|