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 CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/key_value.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{key_value}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Heinrich", "Michael Grosser"]
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
- alias_method :set, :[]=
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)
@@ -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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roman Heinrich