bound 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bound.rb +11 -5
- data/lib/bound/version.rb +1 -1
- data/spec/bound_spec.rb +32 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c59c6c0f35aaaddeab4dfbea0f9987845b3f1be
|
4
|
+
data.tar.gz: 9046059a697cd8300cb0d3b699729f03f9ba0c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0c1d56bb48519bd7fa99a5e1594fa10f1140f694ec16b46b49ded5249a99d74a708302210dc5fc07ec1859d621bb8f2167d105ddc54d80caccb9ac1c902181
|
7
|
+
data.tar.gz: 397d6a4af2cef4b156b638c13d3f02455ddd9254e8e193a7f1cb6aec34b0bf2400c9a691537e80afd38ded7657d0799a6a70982e6bd8c2731dc9881145ce143d
|
data/lib/bound.rb
CHANGED
@@ -55,7 +55,12 @@ class Bound
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def call_on(object)
|
58
|
-
|
58
|
+
method = @name
|
59
|
+
if object.respond_to?(method)
|
60
|
+
object.send method
|
61
|
+
else
|
62
|
+
raise NoMethodError, "undefined method `#{method}' for #{object}"
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def valid?
|
@@ -71,7 +76,7 @@ class Bound
|
|
71
76
|
end
|
72
77
|
|
73
78
|
def inspect
|
74
|
-
|
79
|
+
@value.inspect
|
75
80
|
end
|
76
81
|
end
|
77
82
|
|
@@ -193,6 +198,7 @@ class Bound
|
|
193
198
|
end
|
194
199
|
|
195
200
|
def initialize(hash_or_object = {})
|
201
|
+
@attributes = {}
|
196
202
|
seed hash_or_object
|
197
203
|
validate!
|
198
204
|
end
|
@@ -220,11 +226,11 @@ class Bound
|
|
220
226
|
attribute_class = self.class.attrs[attribute_name]
|
221
227
|
nested_class = self.class.nested_attr_classes[attribute_name]
|
222
228
|
|
223
|
-
|
224
|
-
attribute = instance_variable_get(var)
|
229
|
+
attribute = @attributes[attribute_name]
|
225
230
|
|
226
231
|
unless attribute
|
227
|
-
|
232
|
+
@attributes[attribute_name] = attribute_class.new(attribute_name)
|
233
|
+
attribute = @attributes[attribute_name]
|
228
234
|
attribute.nested_class = nested_class if nested_class
|
229
235
|
end
|
230
236
|
|
data/lib/bound/version.rb
CHANGED
data/spec/bound_spec.rb
CHANGED
@@ -82,8 +82,8 @@ describe Bound do
|
|
82
82
|
let(:user) { User.new(hash) }
|
83
83
|
|
84
84
|
it 'lists all attributes' do
|
85
|
-
assert_match(/name
|
86
|
-
assert_match(/age
|
85
|
+
assert_match(/name=>"foo"/, inspection)
|
86
|
+
assert_match(/age=>23/, inspection)
|
87
87
|
assert_match(/User/, inspection)
|
88
88
|
assert_match(/0x[0-9a-f]+/, inspection)
|
89
89
|
end
|
@@ -237,4 +237,34 @@ describe Bound do
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
|
+
describe 'questionmark suffix' do
|
241
|
+
WonderingUser = Bound.required(:asked?)
|
242
|
+
|
243
|
+
let(:hash) { {:asked? => "YES"} }
|
244
|
+
|
245
|
+
it 'is assign- and readable' do
|
246
|
+
[hash, object].each do |subject|
|
247
|
+
user = WonderingUser.new(subject)
|
248
|
+
assert_equal "YES", user.asked?
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe 'seeding with private methods' do
|
254
|
+
ShyUser = Bound.required(:secret)
|
255
|
+
UserSeed = Class.new do
|
256
|
+
private
|
257
|
+
def secret; 42; end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'fails like the method does not exists' do
|
261
|
+
exception = assert_raises ArgumentError do
|
262
|
+
ShyUser.new(UserSeed.new)
|
263
|
+
end
|
264
|
+
|
265
|
+
assert_match(/missing.+secret/i, exception.message)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
|
240
270
|
end
|