bound 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 142cd96919e530d70c6a0f5d1b53e3c32071c50c
4
- data.tar.gz: 9a0d05eebfeaeb3655968ef2582901c8d787f910
3
+ metadata.gz: 0c59c6c0f35aaaddeab4dfbea0f9987845b3f1be
4
+ data.tar.gz: 9046059a697cd8300cb0d3b699729f03f9ba0c82
5
5
  SHA512:
6
- metadata.gz: 688984f42e9b3c71c120455f54491b55b8f1ef6e038fdd761a7d04fb50895a49a17e6ae6ec9d9cfc4d00eb364c6d6d9b92a20a2a2697725aa0c94ce0d57422af
7
- data.tar.gz: 2b145b620e889c5a247a8918e3f7bb0087718a8e3b11ad6f9d545114d54ec1a067b48b27b36b19b90b96f99859a457edeff156457a225941a7221ecc64594eb4
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
- object.send @name
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
- "#{@name}=#{@value.inspect}"
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
- var = :"@#{attribute_name}"
224
- attribute = instance_variable_get(var)
229
+ attribute = @attributes[attribute_name]
225
230
 
226
231
  unless attribute
227
- attribute = instance_variable_set(var, attribute_class.new(attribute_name))
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
@@ -1,3 +1,3 @@
1
1
  class Bound
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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="foo"/, inspection)
86
- assert_match(/age=23/, inspection)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bound
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum