typed-store 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/typed-store.rb +5 -2
- data/test/test_typed-store.rb +8 -1
- data/typed-store.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGM2Y2MxMWZhZDI2ZTVjOTQxOWJlNjc0YmQ5M2JlMjFlMWMyNTQzOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2ZlMjkxN2NhNTE0MGNkOTE2YTI4Y2M3Y2M3MmIzN2RhOGNiYWVlYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTViZGQ5ZmM2NjI5YWQxNTlhYjNjZDZiZmIwN2FmNjUzYzgxZjIxMWUyNjE0
|
10
|
+
ZjEzZGM1YjI3MmFiNjAwN2JkODM4MWM0N2E5Yzg2ZjQ3NjAzZDc0ZWU3NmQy
|
11
|
+
NDQzNzNlODBmNDc0OTk0MzYxYjBhMzA4MzA4MDlkOGE2OWIxMDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjdhYWJlYmE0MjRjNDMyYTQxYjJjNDkyNGRiYWQ5N2QxMGJhZjhlMTcxMDkx
|
14
|
+
NWM5ZGNkNTZiZmY4YmFhZjc2ZDUxODkxYjViYjc2NTMxZmM4MTg4MGY4ZTI4
|
15
|
+
MzA4YzMyN2QwODgxODY0ZGE1MGJhZTk3YTEwODcwZGQ0ZTgzZDY=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/typed-store.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
module Boolean; end
|
2
|
+
|
1
3
|
module TypedStore
|
2
4
|
extend ActiveSupport::Concern
|
3
5
|
|
@@ -11,13 +13,14 @@ module TypedStore
|
|
11
13
|
key, type = *mapping.first
|
12
14
|
|
13
15
|
define_method "#{key}=" do |value|
|
14
|
-
write_store_attribute(store_attribute, key, value ? value.to_s : nil)
|
16
|
+
write_store_attribute(store_attribute, key, value != nil ? value.to_s : nil)
|
15
17
|
end
|
16
18
|
|
17
19
|
define_method key do
|
18
20
|
value = read_store_attribute(store_attribute, key)
|
19
|
-
return nil
|
21
|
+
return nil if value == nil
|
20
22
|
return value if type == String
|
23
|
+
return value == "true" if type == Boolean
|
21
24
|
return value.to_i if type == Integer
|
22
25
|
return BigDecimal(value) if type == BigDecimal
|
23
26
|
return Time.parse(value) if type == Time
|
data/test/test_typed-store.rb
CHANGED
@@ -24,7 +24,8 @@ class TestClass < ActiveRecord::Base
|
|
24
24
|
{a_dbl: BigDecimal},
|
25
25
|
{a_time: Time},
|
26
26
|
{a_datetime: DateTime},
|
27
|
-
{a_date: Date}
|
27
|
+
{a_date: Date},
|
28
|
+
{a_boolean: Boolean}
|
28
29
|
end
|
29
30
|
|
30
31
|
class TestTypedStore < Test::Unit::TestCase
|
@@ -41,6 +42,7 @@ class TestTypedStore < Test::Unit::TestCase
|
|
41
42
|
subject.a_time = time
|
42
43
|
subject.a_date = date
|
43
44
|
subject.a_datetime = datetime
|
45
|
+
subject.a_boolean = false
|
44
46
|
|
45
47
|
subject.save
|
46
48
|
subject.reload
|
@@ -51,6 +53,7 @@ class TestTypedStore < Test::Unit::TestCase
|
|
51
53
|
assert_equal(time.to_s, subject.a_time.to_s)
|
52
54
|
assert_equal(date.to_s, subject.a_date.to_s)
|
53
55
|
assert_equal(datetime.to_s, subject.a_datetime.to_s)
|
56
|
+
assert_equal(false, subject.a_boolean)
|
54
57
|
end
|
55
58
|
|
56
59
|
should "cast things when set, so they are readable before saving" do
|
@@ -66,6 +69,7 @@ class TestTypedStore < Test::Unit::TestCase
|
|
66
69
|
subject.a_time = time
|
67
70
|
subject.a_date = date
|
68
71
|
subject.a_datetime = datetime
|
72
|
+
subject.a_boolean = true
|
69
73
|
|
70
74
|
assert_equal("this is a test", subject.a_str)
|
71
75
|
assert_equal(12452, subject.a_int)
|
@@ -73,6 +77,7 @@ class TestTypedStore < Test::Unit::TestCase
|
|
73
77
|
assert_equal(time.to_s, subject.a_time.to_s)
|
74
78
|
assert_equal(date.to_s, subject.a_date.to_s)
|
75
79
|
assert_equal(datetime.to_s, subject.a_datetime.to_s)
|
80
|
+
assert_equal(true, subject.a_boolean)
|
76
81
|
end
|
77
82
|
|
78
83
|
should "let you set and get nils" do
|
@@ -84,6 +89,7 @@ class TestTypedStore < Test::Unit::TestCase
|
|
84
89
|
subject.a_time = nil
|
85
90
|
subject.a_date = nil
|
86
91
|
subject.a_datetime = nil
|
92
|
+
subject.a_boolean = nil
|
87
93
|
|
88
94
|
subject.save
|
89
95
|
subject.reload
|
@@ -94,5 +100,6 @@ class TestTypedStore < Test::Unit::TestCase
|
|
94
100
|
assert_equal(nil, subject.a_time)
|
95
101
|
assert_equal(nil, subject.a_date)
|
96
102
|
assert_equal(nil, subject.a_datetime)
|
103
|
+
assert_equal(nil, subject.a_boolean)
|
97
104
|
end
|
98
105
|
end
|
data/typed-store.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: typed-store 0.
|
5
|
+
# stub: typed-store 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "typed-store"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|