smart_properties 1.5.1 → 1.6.0

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: ca9271a922d4b48ac3b9ee04bc27d495bbe138a6
4
- data.tar.gz: ff500a2b185f4a2dd191f21ab2e49ce0cfdd8c50
3
+ metadata.gz: 852c9747f9b84785abfd7fcd978606311cb506c1
4
+ data.tar.gz: 8151988ab1f61eaefa1ba848ff328a92b4157d6e
5
5
  SHA512:
6
- metadata.gz: d509e7283e7dccd7985d3dd79fa84b3385ebe72f39d2ecd29524e92df7c2b9411f5bf0abac445bbb45c2e6a7c2ed38def7b28f714ec3aff3afec38490ca2745a
7
- data.tar.gz: 4b140aed159e23dfe0de83984cee4a702842883be2ffdcf6e0ef6da7a72503df673d77a42a06f4c0e8f96a45fb33a9ed6879372797de438acffd02de0958334b
6
+ metadata.gz: 7e318b3f393636f86718357432df9916dd2a36613e923e1791ae8d34e7ef2aaca80a6ac9c54eac8530f75d0cf35f54fb30378a50c98ba00f02affb658af9bac7
7
+ data.tar.gz: 0dfa80424f99f8fbd9148ade0430a32d9b5bd8f7f9b499d95be64ae2c9943c245524c49204792c806ea3b9dac883b11216d5eefe26c04bd9ffd3d1272d8c2b42
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  rvm:
2
+ - 2.2.0
2
3
  - 1.9.3
3
- - jruby-19mode
4
- - rbx-19mode
4
+ - rbx-2
5
+ - ruby-head
6
+ - jruby-head
5
7
 
6
8
  bundler_args: --without documentation
@@ -21,7 +21,7 @@
21
21
  # :required => true
22
22
  #
23
23
  module SmartProperties
24
- VERSION = "1.5.1"
24
+ VERSION = "1.6.0"
25
25
 
26
26
  class Error < ::ArgumentError; end
27
27
  class ConfigurationError < Error; end
@@ -318,7 +318,7 @@ module SmartProperties
318
318
 
319
319
  # Assign attributes or default values
320
320
  properties.each do |_, property|
321
- value = attrs.fetch(property.name, property.default(self))
321
+ value = attrs.fetch(property.name) { property.default(self) }
322
322
  send(:"#{property.name}=", value) unless value.nil?
323
323
  end
324
324
 
@@ -431,34 +431,45 @@ describe SmartProperties do
431
431
  end
432
432
  end
433
433
 
434
- context 'when used to build a class that has a property called :id whose default value is a lambda statement' do
434
+ context 'when used to build a class that has a property called :id whose default value is a lambda statement for retrieving the object_id' do
435
435
  subject(:klass) do
436
- counter = Class.new.tap do |c|
436
+ Class.new.tap do |c|
437
+ c.send(:include, described_class)
437
438
 
438
- c.class_eval do
439
- def next
440
- @counter ||= 0
441
- @counter += 1
442
- end
439
+ c.instance_eval do
440
+ property :id, :default => lambda { object_id }
443
441
  end
442
+ end
443
+ end
444
+
445
+ context "instances of this class" do
446
+ it "should evaluate the lambda in their own context and thus return a different value for each instance" do
447
+ first_instance = klass.new
448
+ second_instance = klass.new
444
449
 
445
- end.new
450
+ expect(first_instance.id).to_not eq(second_instance.id)
451
+ end
452
+ end
453
+ end
446
454
 
455
+ context 'when used to build a class that has a property called :boom whose default value is a lambda statement that raises an exception' do
456
+ subject(:klass) do
447
457
  Class.new.tap do |c|
448
458
  c.send(:include, described_class)
449
459
 
450
460
  c.instance_eval do
451
- property :id, :default => lambda { counter.next }
461
+ property :boom, :default => lambda { raise 'Boom!' }
452
462
  end
453
463
  end
454
464
  end
455
465
 
456
466
  context "instances of this class" do
457
- it "should have auto-incrementing ids" do
458
- first_instance = klass.new
459
- second_instance = klass.new
467
+ it "should raise during initialization if no other value for :boom has been provided" do
468
+ expect { klass.new }.to raise_error(RuntimeError, 'Boom!')
469
+ end
460
470
 
461
- expect(second_instance.id - first_instance.id).to eq(1)
471
+ it "should not evaluate the lambda expression and thus not raise during initialization if a different value for :boom has been provided" do
472
+ expect { klass.new(boom: 'Everything is just fine!') }.not_to raise_error
462
473
  end
463
474
  end
464
475
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_properties
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Tennhard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-19 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.2.2
82
+ rubygems_version: 2.4.5
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: SmartProperties – Ruby accessors on steroids