key_value 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -40,7 +40,6 @@ Usage
40
40
 
41
41
  TODO
42
42
  ====
43
- - setting / caching of false <-> AR serialize does not handle false
44
43
  - HandlerSocket support
45
44
 
46
45
  Authors
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/key_value.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{key_value}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
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"]
12
- s.date = %q{2011-05-12}
12
+ s.date = %q{2011-05-13}
13
13
  s.email = %q{michael@grosser.it}
14
14
  s.files = [
15
15
  "Gemfile",
data/lib/key_value.rb CHANGED
@@ -2,22 +2,28 @@ require 'active_record'
2
2
 
3
3
  class KeyValue < ActiveRecord::Base
4
4
  VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
5
- validates_presence_of :key, :value
5
+ validates_presence_of :key
6
6
 
7
7
  serialize :value
8
8
 
9
+ # serialize would treat false the same as nil
10
+ def value=(x)
11
+ x = x.to_yaml unless x.nil?
12
+ write_attribute :value, x
13
+ end
14
+
9
15
  def self.get(key)
10
16
  KeyValue.find_by_key(key).try(:value)
11
17
  end
12
18
 
13
19
  def self.set(key, value)
14
- if value
20
+ if value.nil?
21
+ KeyValue.delete_all(:key => key)
22
+ else
15
23
  record = KeyValue.find_by_key(key) || KeyValue.new(:key => key)
16
24
  record.value = value
17
25
  record.save!
18
26
  value
19
- else
20
- KeyValue.delete_all(:key => key)
21
27
  end
22
28
  end
23
29
 
@@ -36,10 +42,10 @@ class KeyValue < ActiveRecord::Base
36
42
 
37
43
  def self.cache(key)
38
44
  value = get(key)
39
- if value
40
- value
41
- else
45
+ if value.nil?
42
46
  set(key, yield)
47
+ else
48
+ value
43
49
  end
44
50
  end
45
51
  end
@@ -23,7 +23,6 @@ describe KeyValue do
23
23
  end
24
24
 
25
25
  it "can set & get false" do
26
- pending
27
26
  KeyValue.set('xxx', false)
28
27
  KeyValue.get('xxx').should == false
29
28
  end
@@ -96,7 +95,6 @@ describe KeyValue do
96
95
  end
97
96
 
98
97
  it "can store false" do
99
- pending
100
98
  KeyValue.cache('xxx'){false}
101
99
  KeyValue.cache('xxx'){true}.should == false
102
100
  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: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roman Heinrich
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-12 00:00:00 +02:00
19
+ date: 2011-05-13 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency