attributed_object 0.2.2 → 0.3

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: 5315a2bd5d12de680f3260699bd93f6e50710590
4
- data.tar.gz: f13238ffdfe4744e02398612b65be619abe55d99
3
+ metadata.gz: 93bb8f83e8a3c78c45869a3b99dbe8daa9f2efb1
4
+ data.tar.gz: 6bb5a36e47af0eccaea12e4c298bd410cb8d0270
5
5
  SHA512:
6
- metadata.gz: 44fce884e880d05bea7dbd9420c56a73f26244692bb9842fccba47c101d6bab07a20e5a4d7a1bf684afecb28eb467442cea7ee23485417a3ed7f07bb1c044156
7
- data.tar.gz: f397ab649017d8c825e181de4348a06a280b55f9431029df48280e53ed5d82fdc94bd6cddf061291d3ae545e8194d0ec644691252cfdaf48832be0582cb078d6
6
+ metadata.gz: 80b26de182c475a28339f7c2d3ac420fa1b36298d620118dc45cfcda8f981c49d1afbc39915cda76cafca16255cbbe3dc94c9f4e1ed8a40b853e428f37cdbc3a
7
+ data.tar.gz: 6ac411f219a66a1c90d71964b86959399dfa5c2c06e84bca6a1122791596e3ec51a948f3a83c9407ffdaead18031199b0c8a4abf30fa5450ea68c771f73a912d
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
  .idea
19
19
  .ruby-version
20
+
21
+ .DS_Store
data/README.md CHANGED
@@ -155,6 +155,7 @@ end
155
155
  default_to: AttributedObject::Unset, # AttributedObject::Unset | any value | AttributedObject::TypeDefaults
156
156
  ignore_extra_keys: false, # false | true
157
157
  coerce_blanks_to_nil: false, # false | true
158
+ disallow: AttributedObject::Unset, # AttributedObject::Unset | any value
158
159
  }
159
160
  ```
160
161
 
@@ -214,9 +215,24 @@ WithExtraOptions.new(foo: 'asd', something: 'bar') # this will not throw an erro
214
215
  This will cause blank strings to equal nil after coercion for all non-string types.
215
216
  For example an integer will not become '' => 0, but instead '' => nil.
216
217
 
218
+ ### disallow: nil
219
+ The global `disallow` option makes it easier to prevent nil in the full model.
220
+ ```ruby
221
+ class WithExtraOptions
222
+ include AttributedObject::Strict
223
+ attributed_object disallow: nil
224
+
225
+ attribute :foo
226
+ end
227
+ WithExtraOptions.new(foo: nil) # this will not throw an error
228
+ ```
229
+
217
230
  ## Benchmark
218
231
 
219
232
  Of course the other gems can do quite a bit more, but this is interesting anyway.
220
233
  (see benchmark_attributed_object.rb)
221
234
  Result: Attributed Object is quite a bit fast (2-3x) than other gems for the specific use cases.
222
235
 
236
+ ### keywords
237
+
238
+ ruby, AttributedObject, attributed object, attributed_object, value, domain driven design, ddd
@@ -13,7 +13,8 @@ module AttributedObject
13
13
  @attributed_object_options = {
14
14
  default_to: Unset,
15
15
  ignore_extra_keys: false,
16
- coerce_blanks_to_nil: false
16
+ coerce_blanks_to_nil: false,
17
+ disallow: Unset
17
18
  }.merge(parent_ops)
18
19
  end
19
20
 
@@ -33,6 +34,10 @@ module AttributedObject
33
34
  end
34
35
  end
35
36
 
37
+ if disallow == Unset
38
+ disallow = attributed_object_options.fetch(:disallow)
39
+ end
40
+
36
41
  _attributed_object_check_type_supported!(type_info)
37
42
 
38
43
  attribute_defs[attr_name] = {
@@ -1,3 +1,3 @@
1
1
  module AttributedObject
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -157,6 +157,22 @@ describe AttributedObject do
157
157
  expect(FooWithExtra.new(bar: 12, not_defined: 'asd').attributes).to eq(bar: 12)
158
158
  end
159
159
  end
160
+
161
+ describe 'disallow' do
162
+ it 'gives default to disallow' do
163
+ class FooWithExtra
164
+ include AttributedObject::Strict
165
+ attributed_object disallow: nil
166
+ attribute :bar, :integer
167
+ attribute :has_other_disallow, :integer, disallow: 0
168
+ end
169
+
170
+ expect { FooWithExtra.new(bar: 1, has_other_disallow: 1) }.not_to raise_error
171
+ expect { FooWithExtra.new(bar: 1, has_other_disallow: nil) }.not_to raise_error
172
+ expect { FooWithExtra.new(bar: nil, has_other_disallow: 1) }.to raise_error(AttributedObject::DisallowedValueError)
173
+ expect { FooWithExtra.new(bar: 1, has_other_disallow: 0) }.to raise_error(AttributedObject::DisallowedValueError)
174
+ end
175
+ end
160
176
  end
161
177
 
162
178
  it 'throws an error for unknown attributes' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attributed_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaap Groeneveld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-13 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler