smart_properties 1.6.0 → 1.6.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: 852c9747f9b84785abfd7fcd978606311cb506c1
4
- data.tar.gz: 8151988ab1f61eaefa1ba848ff328a92b4157d6e
3
+ metadata.gz: b925a25ffc3986a157e22c2b1e15d14fffe83ac2
4
+ data.tar.gz: 257d8a8aa05874ae0dcc43c00a60142c4fd809b7
5
5
  SHA512:
6
- metadata.gz: 7e318b3f393636f86718357432df9916dd2a36613e923e1791ae8d34e7ef2aaca80a6ac9c54eac8530f75d0cf35f54fb30378a50c98ba00f02affb658af9bac7
7
- data.tar.gz: 0dfa80424f99f8fbd9148ade0430a32d9b5bd8f7f9b499d95be64ae2c9943c245524c49204792c806ea3b9dac883b11216d5eefe26c04bd9ffd3d1272d8c2b42
6
+ metadata.gz: 6ad62801456bd554a4cf3984438490d4dadb9054a29a9dd16d4ffc87206a3a1d1abbeee25fdffc60810a5d1451b390882541f5b5540f2230d32b19f6f3828d24
7
+ data.tar.gz: d2557a94805341d73a358bacb2c3b0daa9a5c2916bc288789c7db2a0c0d4f28eb0b2890d075ec56cfde6f0dc3be3770a74a916ea673183e66712361d2f728335
@@ -21,7 +21,7 @@
21
21
  # :required => true
22
22
  #
23
23
  module SmartProperties
24
- VERSION = "1.6.0"
24
+ VERSION = "1.6.1"
25
25
 
26
26
  class Error < ::ArgumentError; end
27
27
  class ConfigurationError < Error; end
@@ -315,16 +315,28 @@ module SmartProperties
315
315
  def initialize(attrs = {}, &block)
316
316
  attrs ||= {}
317
317
  properties = self.class.properties.each.to_a
318
+ missing_properties = []
318
319
 
319
320
  # Assign attributes or default values
320
321
  properties.each do |_, property|
321
- value = attrs.fetch(property.name) { property.default(self) }
322
- send(:"#{property.name}=", value) unless value.nil?
322
+ if attrs.key?(property.name)
323
+ instance_variable_set("@#{property.name}", property.prepare(attrs[property.name], self))
324
+ else
325
+ missing_properties.push(property)
326
+ end
323
327
  end
324
328
 
325
329
  # Exectue configuration block
326
330
  block.call(self) if block
327
331
 
332
+ # Set defaults
333
+ missing_properties.each do |property|
334
+ variable = "@#{property.name}"
335
+ if instance_variable_get(variable).nil? && !(default_value = property.default(self)).nil?
336
+ instance_variable_set(variable, property.prepare(default_value, self))
337
+ end
338
+ end
339
+
328
340
  # Check presence of all required properties
329
341
  faulty_properties =
330
342
  properties.select { |_, property| property.required?(self) && send(property.name).nil? }.map(&:last)
@@ -468,9 +468,13 @@ describe SmartProperties do
468
468
  expect { klass.new }.to raise_error(RuntimeError, 'Boom!')
469
469
  end
470
470
 
471
- it "should not evaluate the lambda expression and thus not raise during initialization if a different value for :boom has been provided" do
471
+ it "should not evaluate the lambda expression and thus not raise during initialization if a different value for :boom has been provided as a parameter" do
472
472
  expect { klass.new(boom: 'Everything is just fine!') }.not_to raise_error
473
473
  end
474
+
475
+ it "should not evaluate the lambda expression and thus not raise during initialization if a different value for :boom has been provided in an initilization block" do
476
+ expect { klass.new { |inst| inst.boom = 'Everything is just fine!' } }.not_to raise_error
477
+ end
474
478
  end
475
479
  end
476
480
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_properties
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Tennhard