id 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -0
- data/Gemfile.lock +2 -0
- data/README.md +1 -1
- data/Rakefile +7 -0
- data/id.gemspec +2 -1
- data/lib/id/boolean.rb +7 -1
- data/lib/id/coercion.rb +3 -0
- data/lib/id/field.rb +3 -1
- data/spec/lib/id/boolean_spec.rb +11 -0
- metadata +42 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc41c07c98e64d9acb78e1ca43310aa60cbd288d
|
4
|
+
data.tar.gz: 0fa48ccf04acfdb811a20e5445fdbf8fe44229e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b468113fb6e759b3dbb48e2f41d5b6da971a65fbff3486d9168cbc4b54caa6584169270cdcefa88aced8b42b0ce00147b69809f315e8cfa61baaa46fafde1f
|
7
|
+
data.tar.gz: c4f2e459ea3fe379f0f9e4e96a61fb84c200166afcb01489a216b8bb832036230ba693cd0c0d790a785455f8e9c8f92e4054da4aab69f69225c50964a8c53000
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
id
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -38,6 +38,7 @@ GEM
|
|
38
38
|
i18n (~> 0.6.0)
|
39
39
|
multi_json (1.7.3)
|
40
40
|
optional (0.0.7)
|
41
|
+
rake (10.3.2)
|
41
42
|
rest-client (1.6.7)
|
42
43
|
mime-types (>= 1.16)
|
43
44
|
rspec (2.13.0)
|
@@ -68,6 +69,7 @@ DEPENDENCIES
|
|
68
69
|
coveralls
|
69
70
|
id!
|
70
71
|
mocha
|
72
|
+
rake
|
71
73
|
rspec
|
72
74
|
simplecov
|
73
75
|
test-unit
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# id
|
2
|
-
### simple models based on hashes
|
2
|
+
### simple, immutable models based on hashes
|
3
3
|
|
4
4
|
JSON is a great way to transfer data between systems, and it's easy to parse into a Ruby hash. But sometimes it's nice to have actual methods to call when you want to get attributes from your data, rather than coupling your entire codebase to the hash representation by littering it with calls to `fetch` or `[]`. The same goes for BSON documents stored in Mongo.
|
5
5
|
|
data/Rakefile
ADDED
data/id.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'id'
|
3
|
-
s.version = '0.1'
|
3
|
+
s.version = '0.1.1'
|
4
4
|
s.date = '2013-03-28'
|
5
5
|
s.summary = "Simple models based on hashes"
|
6
6
|
s.description = "Easily convert hashes to Ruby objects. Originally developed at www.onthebeach.co.uk."
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency "activesupport"
|
18
18
|
s.add_dependency "activemodel"
|
19
19
|
|
20
|
+
s.add_development_dependency "rake"
|
20
21
|
s.add_development_dependency "rspec"
|
21
22
|
s.add_development_dependency "mocha"
|
22
23
|
s.add_development_dependency "simplecov"
|
data/lib/id/boolean.rb
CHANGED
@@ -2,7 +2,13 @@ module Id::Boolean
|
|
2
2
|
extend self
|
3
3
|
|
4
4
|
def parse(value)
|
5
|
-
|
5
|
+
case value
|
6
|
+
when String then ['yes', 'true', '1'].include?(value.to_s.downcase)
|
7
|
+
when Symbol then ['yes', 'true', '1'].include?(value.to_s.downcase)
|
8
|
+
when Fixnum then value != 0
|
9
|
+
when TrueClass then true
|
10
|
+
else false
|
11
|
+
end
|
6
12
|
end
|
7
13
|
|
8
14
|
end
|
data/lib/id/coercion.rb
CHANGED
@@ -36,3 +36,6 @@ Id::Coercion.register String, Float, &:to_f
|
|
36
36
|
Id::Coercion.register String, Date, &Date.method(:parse)
|
37
37
|
Id::Coercion.register String, Time, &Time.method(:parse)
|
38
38
|
Id::Coercion.register String, Id::Boolean, &Id::Boolean.method(:parse)
|
39
|
+
Id::Coercion.register Fixnum, Id::Boolean, &Id::Boolean.method(:parse)
|
40
|
+
Id::Coercion.register TrueClass, Id::Boolean, &Id::Boolean.method(:parse)
|
41
|
+
Id::Coercion.register FalseClass, Id::Boolean, &Id::Boolean.method(:parse)
|
data/lib/id/field.rb
CHANGED
@@ -19,7 +19,9 @@ module Id::Field
|
|
19
19
|
|
20
20
|
def define_field!(definition)
|
21
21
|
send :define_method, definition.name do
|
22
|
-
_data[definition.key]
|
22
|
+
_data[definition.key].tap do |value|
|
23
|
+
fail Id::MissingAttributeError, [self, definition] if value.nil?
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
data/spec/lib/id/boolean_spec.rb
CHANGED
@@ -31,8 +31,19 @@ describe Id::Boolean do
|
|
31
31
|
expect(b).to be_true
|
32
32
|
end
|
33
33
|
|
34
|
+
it 'parses trueclass as true' do
|
35
|
+
b = Id::Boolean.parse(true)
|
36
|
+
expect(b).to be_true
|
37
|
+
end
|
38
|
+
|
34
39
|
it 'parses everything else as false' do
|
35
40
|
b = Id::Boolean.parse(:cottage_cheese)
|
36
41
|
expect(b).to be_false
|
37
42
|
end
|
43
|
+
|
44
|
+
it 'works with default values' do
|
45
|
+
test_class = Class.new { include Id::Model; field :foo, type: Id::Boolean, default: false }
|
46
|
+
expect(test_class.new.foo).to be_false
|
47
|
+
end
|
48
|
+
|
38
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Dunphy
|
@@ -15,126 +15,140 @@ dependencies:
|
|
15
15
|
name: optional
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: money
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: activesupport
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: activemodel
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '0'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: rspec
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
73
87
|
requirements:
|
74
|
-
- -
|
88
|
+
- - ">="
|
75
89
|
- !ruby/object:Gem::Version
|
76
90
|
version: '0'
|
77
91
|
type: :development
|
78
92
|
prerelease: false
|
79
93
|
version_requirements: !ruby/object:Gem::Requirement
|
80
94
|
requirements:
|
81
|
-
- -
|
95
|
+
- - ">="
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: mocha
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
87
101
|
requirements:
|
88
|
-
- -
|
102
|
+
- - ">="
|
89
103
|
- !ruby/object:Gem::Version
|
90
104
|
version: '0'
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
|
-
- -
|
109
|
+
- - ">="
|
96
110
|
- !ruby/object:Gem::Version
|
97
111
|
version: '0'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: simplecov
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- -
|
116
|
+
- - ">="
|
103
117
|
- !ruby/object:Gem::Version
|
104
118
|
version: '0'
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
|
-
- -
|
123
|
+
- - ">="
|
110
124
|
- !ruby/object:Gem::Version
|
111
125
|
version: '0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: coveralls
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
|
-
- -
|
130
|
+
- - ">="
|
117
131
|
- !ruby/object:Gem::Version
|
118
132
|
version: '0'
|
119
133
|
type: :development
|
120
134
|
prerelease: false
|
121
135
|
version_requirements: !ruby/object:Gem::Requirement
|
122
136
|
requirements:
|
123
|
-
- -
|
137
|
+
- - ">="
|
124
138
|
- !ruby/object:Gem::Version
|
125
139
|
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: test-unit
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
129
143
|
requirements:
|
130
|
-
- -
|
144
|
+
- - ">="
|
131
145
|
- !ruby/object:Gem::Version
|
132
146
|
version: '0'
|
133
147
|
type: :development
|
134
148
|
prerelease: false
|
135
149
|
version_requirements: !ruby/object:Gem::Requirement
|
136
150
|
requirements:
|
137
|
-
- -
|
151
|
+
- - ">="
|
138
152
|
- !ruby/object:Gem::Version
|
139
153
|
version: '0'
|
140
154
|
description: Easily convert hashes to Ruby objects. Originally developed at www.onthebeach.co.uk.
|
@@ -145,13 +159,16 @@ executables: []
|
|
145
159
|
extensions: []
|
146
160
|
extra_rdoc_files: []
|
147
161
|
files:
|
148
|
-
- .gitignore
|
149
|
-
- .rspec
|
150
|
-
- .ruby-
|
162
|
+
- ".gitignore"
|
163
|
+
- ".rspec"
|
164
|
+
- ".ruby-gemset"
|
165
|
+
- ".ruby-version"
|
166
|
+
- ".travis.yml"
|
151
167
|
- Gemfile
|
152
168
|
- Gemfile.lock
|
153
169
|
- LICENSE.md
|
154
170
|
- README.md
|
171
|
+
- Rakefile
|
155
172
|
- id.gemspec
|
156
173
|
- lib/id.rb
|
157
174
|
- lib/id/active_model.rb
|
@@ -195,17 +212,17 @@ require_paths:
|
|
195
212
|
- lib
|
196
213
|
required_ruby_version: !ruby/object:Gem::Requirement
|
197
214
|
requirements:
|
198
|
-
- -
|
215
|
+
- - ">="
|
199
216
|
- !ruby/object:Gem::Version
|
200
217
|
version: '0'
|
201
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
219
|
requirements:
|
203
|
-
- -
|
220
|
+
- - ">="
|
204
221
|
- !ruby/object:Gem::Version
|
205
222
|
version: '0'
|
206
223
|
requirements: []
|
207
224
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.0
|
225
|
+
rubygems_version: 2.2.0
|
209
226
|
signing_key:
|
210
227
|
specification_version: 4
|
211
228
|
summary: Simple models based on hashes
|