attributor 5.0 → 5.0.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/attributor/hash_dsl_compiler.rb +1 -1
- data/lib/attributor/types/hash.rb +3 -5
- data/lib/attributor/types/model.rb +6 -1
- data/lib/attributor/version.rb +1 -1
- data/spec/support/models.rb +1 -0
- data/spec/types/model_spec.rb +9 -4
- 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: e92945289cab58f688cbad5df9d032fa684537b3
|
4
|
+
data.tar.gz: 53c15208c223f49ae8c05fdeebb962e31cc9c63e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 957400d332d6091f4f288c338ca9564004a9ca07b7d50355a8870c004f4419c3879e35c997aa4cdcdd4e92fd1301935c860de9c92318ae94d1d7af9f7208cf72
|
7
|
+
data.tar.gz: 7a189aa4fac7c5c7263e130a25b52515fb3de6717e652cbc7f5fd00d1c95acf48caaad70771b151b96365e616a9c6e384b873de2abfe68604a2b4b804cc4c0b0
|
data/CHANGELOG.md
CHANGED
@@ -590,11 +590,9 @@ module Attributor
|
|
590
590
|
end
|
591
591
|
end
|
592
592
|
end
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
errors.push *validation_errors unless validation_errors.empty?
|
597
|
-
end
|
593
|
+
self.class.requirements.each_with_object(ret) do |req, errors|
|
594
|
+
validation_errors = req.validate( @contents , context)
|
595
|
+
errors.push *validation_errors unless validation_errors.empty?
|
598
596
|
end
|
599
597
|
ret
|
600
598
|
end
|
@@ -131,7 +131,7 @@ module Attributor
|
|
131
131
|
|
132
132
|
context = [context] if context.is_a? ::String
|
133
133
|
|
134
|
-
self.class.attributes.each_with_object(Array.new) do |(sub_attribute_name, sub_attribute), errors|
|
134
|
+
ret = self.class.attributes.each_with_object(Array.new) do |(sub_attribute_name, sub_attribute), errors|
|
135
135
|
sub_context = self.class.generate_subcontext(context,sub_attribute_name)
|
136
136
|
|
137
137
|
value = self.__send__(sub_attribute_name)
|
@@ -141,6 +141,11 @@ module Attributor
|
|
141
141
|
|
142
142
|
errors.push *sub_attribute.validate(value, sub_context)
|
143
143
|
end
|
144
|
+
self.class.requirements.each_with_object(ret) do |req, errors|
|
145
|
+
validation_errors = req.validate( @contents , context)
|
146
|
+
errors.push *validation_errors unless validation_errors.empty?
|
147
|
+
end
|
148
|
+
ret
|
144
149
|
ensure
|
145
150
|
@validating = false
|
146
151
|
end
|
data/lib/attributor/version.rb
CHANGED
data/spec/support/models.rb
CHANGED
@@ -83,6 +83,7 @@ class Address < Attributor::Model
|
|
83
83
|
attribute :name, String, example: /\w+/
|
84
84
|
attribute :state, String, values: %w{OR CA}
|
85
85
|
attribute :person, Person, example: proc { |address, context| Person.example(context, address: address) }
|
86
|
+
requires :name
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
data/spec/types/model_spec.rb
CHANGED
@@ -246,7 +246,7 @@ describe Attributor::Model do
|
|
246
246
|
context 'loading with default values' do
|
247
247
|
let(:reference) { Post }
|
248
248
|
let(:options) { {reference: reference} }
|
249
|
-
|
249
|
+
|
250
250
|
let(:attribute_definition) do
|
251
251
|
proc do
|
252
252
|
attribute :title
|
@@ -255,10 +255,10 @@ describe Attributor::Model do
|
|
255
255
|
end
|
256
256
|
|
257
257
|
let(:struct) { Attributor::Struct.construct(attribute_definition, options)}
|
258
|
-
|
258
|
+
|
259
259
|
let(:data) { {title: 'my post'} }
|
260
|
-
|
261
|
-
subject(:loaded) { struct.load(data) }
|
260
|
+
|
261
|
+
subject(:loaded) { struct.load(data) }
|
262
262
|
|
263
263
|
|
264
264
|
it 'validates' do
|
@@ -372,6 +372,11 @@ describe Attributor::Model do
|
|
372
372
|
end
|
373
373
|
end
|
374
374
|
|
375
|
+
context 'for models using the "requires" DSL' do
|
376
|
+
subject(:address) { Address.load(state: 'CA') }
|
377
|
+
its(:validate) { should_not be_empty }
|
378
|
+
its(:validate) { should include "Key name is required for $." }
|
379
|
+
end
|
375
380
|
context 'for models with circular sub-attributes' do
|
376
381
|
context 'that are valid' do
|
377
382
|
subject(:person) { Person.example }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attributor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Blanquer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-12-
|
12
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -369,7 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
369
369
|
version: '0'
|
370
370
|
requirements: []
|
371
371
|
rubyforge_project:
|
372
|
-
rubygems_version: 2.4.5
|
372
|
+
rubygems_version: 2.4.5.1
|
373
373
|
signing_key:
|
374
374
|
specification_version: 4
|
375
375
|
summary: A powerful attribute and type management library for Ruby
|