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 +4 -4
- data/.travis.yml +4 -2
- data/lib/smart_properties.rb +2 -2
- data/spec/smart_properties_spec.rb +24 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 852c9747f9b84785abfd7fcd978606311cb506c1
|
4
|
+
data.tar.gz: 8151988ab1f61eaefa1ba848ff328a92b4157d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e318b3f393636f86718357432df9916dd2a36613e923e1791ae8d34e7ef2aaca80a6ac9c54eac8530f75d0cf35f54fb30378a50c98ba00f02affb658af9bac7
|
7
|
+
data.tar.gz: 0dfa80424f99f8fbd9148ade0430a32d9b5bd8f7f9b499d95be64ae2c9943c245524c49204792c806ea3b9dac883b11216d5eefe26c04bd9ffd3d1272d8c2b42
|
data/.travis.yml
CHANGED
data/lib/smart_properties.rb
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
# :required => true
|
22
22
|
#
|
23
23
|
module SmartProperties
|
24
|
-
VERSION = "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
|
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
|
-
|
436
|
+
Class.new.tap do |c|
|
437
|
+
c.send(:include, described_class)
|
437
438
|
|
438
|
-
c.
|
439
|
-
|
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
|
-
|
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 :
|
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
|
458
|
-
|
459
|
-
|
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
|
-
|
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.
|
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:
|
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.
|
82
|
+
rubygems_version: 2.4.5
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: SmartProperties – Ruby accessors on steroids
|