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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGQ5N2EyNjljZTZjMTViZmNlYjEwOTAzNzY4ZGJhMTdjYWQ5ZTEzNw==
4
+ MGM2Y2MxMWZhZDI2ZTVjOTQxOWJlNjc0YmQ5M2JlMjFlMWMyNTQzOQ==
5
5
  data.tar.gz: !binary |-
6
- NWJmMzQxY2Q2ZGYyNjJjZjEzYzFjZmY1ZDcxMzMyN2UxMDI0NmYzMw==
6
+ N2ZlMjkxN2NhNTE0MGNkOTE2YTI4Y2M3Y2M3MmIzN2RhOGNiYWVlYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmRhY2Y3YTQyMzhmNjgwYjZhOGZlOTY0MTZhNDRiNWIyYmIyMDJlNjY5OTg3
10
- ZjAwMGUyYjQ5MjM5Y2QyMjE4ODdhODMzNWY1YWEwN2QzOGZmOWM0ZGMxMTE0
11
- NGJhZDEwNmZhMmFjYTQxYTJkNDM0YjhjZjYzOTllNjJkYzU5NGU=
9
+ NTViZGQ5ZmM2NjI5YWQxNTlhYjNjZDZiZmIwN2FmNjUzYzgxZjIxMWUyNjE0
10
+ ZjEzZGM1YjI3MmFiNjAwN2JkODM4MWM0N2E5Yzg2ZjQ3NjAzZDc0ZWU3NmQy
11
+ NDQzNzNlODBmNDc0OTk0MzYxYjBhMzA4MzA4MDlkOGE2OWIxMDI=
12
12
  data.tar.gz: !binary |-
13
- N2RmNThkMjFiYTNmNDAyNzhkNDJmNGZlNTIwOTNkY2M4ZDMyZDliYjg5NmY0
14
- YTQzM2Y0NWQwZDc5OTMxYmQwZTg4MzU5M2NkMjUyOTk1NTA4ZmE3YzM1ZjJl
15
- YTk1ZTI2Y2FlZDhkYmRmMDg4ZjU3ODkwMTFiNWFjMzliNDE1ZDg=
13
+ YjdhYWJlYmE0MjRjNDMyYTQxYjJjNDkyNGRiYWQ5N2QxMGJhZjhlMTcxMDkx
14
+ NWM5ZGNkNTZiZmY4YmFhZjc2ZDUxODkxYjViYjc2NTMxZmM4MTg4MGY4ZTI4
15
+ MzA4YzMyN2QwODgxODY0ZGE1MGJhZTk3YTEwODcwZGQ0ZTgzZDY=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.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 unless value
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
@@ -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.2.0 ruby lib
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.2.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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Baldry