smart_properties 1.11.0 → 1.12.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: bc7370198b5c366256110bdf6dc2589491047c26
4
- data.tar.gz: 149815152075ee2e125c4f55bb9b8916a1be631d
3
+ metadata.gz: 308f2acd5b26ff6c0d5f008835d1ed86ba18218c
4
+ data.tar.gz: d3744f7a5be843235043d5f04d290693016e0877
5
5
  SHA512:
6
- metadata.gz: aa4d68dfabfd0b6cedbb2f2caa6a2105bd3ddd101bde45d3d2fef0fd52527b2ec2a3556c7b58bdf95dcf8075fc6917197e8cfda4d31795c630b6ed6a4a17f6f8
7
- data.tar.gz: 895e03d0ad7aa8d96a76ce9c92e2cf72cd1ad558aeb99aaa644dc7c32fcff87f0f7db10631addf71b2193996a63b5ecf8d41a9ee66401cc6c56819fedebc042c
6
+ metadata.gz: 7f62e2aee8c528d1d6387e5e51594a998e6ef81c9afdc17935e51389c774f769eaeadc7cd3d55b0b7242c50730be371d2c843f26a4ccfe4e0d34c9f5fb72bb35
7
+ data.tar.gz: 34fc69a7afb5635f32201fb8e3c9ca132177fe628ffcd3b7b3f11462dd1901360041234542dc9998b8fd04ab8b62593ed07308b834d5f482152fd17955150435
data/README.md CHANGED
@@ -200,6 +200,14 @@ class Article
200
200
  end
201
201
  ```
202
202
 
203
+ Alternatively you can also use the `property!` method.
204
+
205
+ ```ruby
206
+ class Article
207
+ property! :title
208
+ end
209
+ ```
210
+
203
211
  The decision whether or not a property is required can also be delayed and
204
212
  evaluated at runtime by providing a block instead of a boolean value. The
205
213
  example below shows how to implement a class that has two properties, `name`
@@ -83,6 +83,12 @@ module SmartProperties
83
83
  properties[name] = Property.define(self, name, options)
84
84
  end
85
85
  protected :property
86
+
87
+ def property!(name, options = {})
88
+ options[:required] = true
89
+ property(name, options)
90
+ end
91
+ protected :property!
86
92
  end
87
93
 
88
94
  class << self
@@ -1,3 +1,3 @@
1
1
  module SmartProperties
2
- VERSION = "1.11.0"
2
+ VERSION = "1.12.0"
3
3
  end
@@ -39,6 +39,44 @@ RSpec.describe SmartProperties do
39
39
  end
40
40
  end
41
41
 
42
+ context "when building a class that has a property! which is required and has no default" do
43
+ subject(:klass) { DummyClass.new { property! :title } }
44
+
45
+ context 'an instance of this class' do
46
+ it 'should have the correct title when provided with a title during initialization' do
47
+ instance = klass.new title: 'Lorem Ipsum'
48
+ expect(instance.title).to eq('Lorem Ipsum')
49
+ expect(instance[:title]).to eq('Lorem Ipsum')
50
+
51
+ instance = klass.new { |i| i.title = 'Lorem Ipsum' }
52
+ expect(instance.title).to eq('Lorem Ipsum')
53
+ expect(instance[:title]).to eq('Lorem Ipsum')
54
+ end
55
+
56
+ it "should raise an error stating that required properties are missing when initialized without a title" do
57
+ exception = SmartProperties::InitializationError
58
+ message = "Dummy requires the following properties to be set: title"
59
+ further_expectations = lambda { |error| expect(error.to_hash[:title]).to eq('must be set') }
60
+
61
+ expect { klass.new }.to raise_error(exception, message, &further_expectations)
62
+ expect { klass.new {} }.to raise_error(exception, message, &further_expectations)
63
+ end
64
+
65
+ it "should not allow to set nil as the property's value" do
66
+ instance = klass.new title: 'Lorem Ipsum'
67
+
68
+ exception = SmartProperties::MissingValueError
69
+ message = "Dummy requires the property title to be set"
70
+ further_expectations = lambda do |error|
71
+ expect(error.to_hash[:title]).to eq('must be set')
72
+ end
73
+
74
+ expect { instance.title = nil }.to raise_error(exception, message, &further_expectations)
75
+ expect { instance[:title] = nil }.to raise_error(exception, message, &further_expectations)
76
+ end
77
+ end
78
+ end
79
+
42
80
  context "when building a class that has a property name which is only required if the property anonymous is set to false" do
43
81
  subject(:klass) do
44
82
  DummyClass.new do
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.11.0
4
+ version: 1.12.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: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec