praxis-blueprints 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54c80c09733228cb18f5fdc35ae05054bd0727a4
4
- data.tar.gz: 90eba917e0f3d2651d840333fe5d81b94a13428b
3
+ metadata.gz: 97b7352ecab8d56459df9325ca4950ef87f8ebb1
4
+ data.tar.gz: bde131b221dd5535017d22a7b54c592565a7d27c
5
5
  SHA512:
6
- metadata.gz: 5f307971333a02b445884d4e3a514b4a20c4bca46fa9fe38aed65e7fec34b717f0a02afbd520ef0ac3d601a396b7554f6af73cfe1a7cc23bb56ef76b0b2ba814
7
- data.tar.gz: 1d375284f3af2b1d32ea79b06c0677b3588696d377840297ebfa71a473f79286bbed6ce7d5a4ef85b3c92988f1b4062df108be8cff48b5141aebf8f3d605d5f3
6
+ metadata.gz: a48ba08bf752647dec66aaf024d230d2e97ad26d157c5e0f2969ace71c23b2d3de14c27d8fd2aa694c717246b47b43b60ee971e0f4ef6102f880b5e636a4e781
7
+ data.tar.gz: 59ff0611ce4a0322f7bda51af02928a482bc556a4a2f1362a126ab59ddbdbc58612bf5014047ecd06c3821822154b91cd5ca3976f81972101bf09b7a2c384fc0
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## next
4
4
 
5
- * next thing here
5
+ * `Blueprint` readers now always `load` the value for an attribute before returning it.
6
6
 
7
7
  ## 1.1.0
8
8
 
@@ -82,7 +82,7 @@ module Praxis
82
82
  opts[:reference] = self
83
83
  end
84
84
 
85
- @options = opts
85
+ @options.merge!(opts)
86
86
  @block = block
87
87
  end
88
88
 
@@ -274,21 +274,26 @@ module Praxis
274
274
  else
275
275
  value = @object.send(name)
276
276
  return value if value.nil? || value.kind_of?(attribute.type)
277
- attribute.type.new(value)
277
+ attribute.type.load(value)
278
278
  end
279
279
  end
280
280
  end
281
281
 
282
282
  def self.define_direct_reader!(name)
283
- module_eval <<-RUBY, __FILE__, __LINE__ + 1
284
- def #{name}
285
- if @decorators && @decorators.respond_to?(:#{name})
286
- @decorators.#{name}
287
- else
288
- @object.#{name}
289
- end
290
- end
291
- RUBY
283
+ attribute = self.attributes[name]
284
+ # TODO: profile and optimize
285
+ # because we use the attribute in the reader,
286
+ # it's likely faster to use define_method here
287
+ # than module_eval, but we should make sure.
288
+ define_method(name) do
289
+ if @decorators && @decorators.respond_to?(name)
290
+ @decorators.send(name)
291
+ else
292
+ value = @object.__send__(name)
293
+ return value if value.nil? || value.kind_of?(attribute.type)
294
+ attribute.load(value)
295
+ end
296
+ end
292
297
  end
293
298
 
294
299
  def self.generate_master_view!
@@ -304,14 +309,12 @@ module Praxis
304
309
 
305
310
 
306
311
  def validate(context=Attributor::DEFAULT_ROOT_CONTEXT)
307
-
308
312
  raise ArgumentError, "Invalid context received (nil) while validating value of type #{self.name}" if context == nil
309
313
  context = [context] if context.is_a? ::String
310
314
 
311
315
  raise "validation conflict" if @validating
312
316
  @validating = true
313
317
 
314
-
315
318
  self.class.attributes.each_with_object(Array.new) do |(sub_attribute_name, sub_attribute), errors|
316
319
  sub_context = self.class.generate_subcontext(context,sub_attribute_name)
317
320
  value = self.send(sub_attribute_name)
@@ -1,3 +1,3 @@
1
1
  module Praxis
2
- BLUEPRINTS_VERSION = "1.1.0"
2
+ BLUEPRINTS_VERSION = "1.1.1"
3
3
  end
@@ -309,7 +309,7 @@ describe Praxis::Blueprint do
309
309
  person.address.should_receive(:state).and_raise("Kaboom")
310
310
  expect {
311
311
  person.render(view_name, context: ['special_root'])
312
- }.to raise_error(/Error while dumping attribute state of type Address for context special_root.address .*. Reason: .*Kaboom/)
312
+ }.to raise_error(/Error while dumping attribute state of type Address for context special_root.address. Reason: .*Kaboom/)
313
313
  end
314
314
  end
315
315
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praxis-blueprints
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer