attributor 5.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de74a91670c3d4d2ab545ed984f7a8e04ad258bc
4
- data.tar.gz: 6d1764a9765d136fe1439ec0cd46e54519aaf07f
3
+ metadata.gz: e92945289cab58f688cbad5df9d032fa684537b3
4
+ data.tar.gz: 53c15208c223f49ae8c05fdeebb962e31cc9c63e
5
5
  SHA512:
6
- metadata.gz: c2899ff383f44c4266725b69e35a60707885dd648ca6f00e75fb5f515b0946fbe0a8192c9f822891a0222aeaa572b24f50d05bfeff9b7adac74e275147f7748b
7
- data.tar.gz: 9d6823ce40583045dc223d5f5e348d5f276840cf7ff211880d8d491521de16484ccd338e3677a4be665defb55fdccf5bdc09893c1b667b6489892ae3715696cf
6
+ metadata.gz: 957400d332d6091f4f288c338ca9564004a9ca07b7d50355a8870c004f4419c3879e35c997aa4cdcdd4e92fd1301935c860de9c92318ae94d1d7af9f7208cf72
7
+ data.tar.gz: 7a189aa4fac7c5c7263e130a25b52515fb3de6717e652cbc7f5fd00d1c95acf48caaad70771b151b96365e616a9c6e384b873de2abfe68604a2b4b804cc4c0b0
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## next
4
4
 
5
+ ## 5.0.1
6
+
7
+ * Fix bug that made Struct/Models skip validation of requirements using the `requires` DSL
5
8
 
6
9
  ## 5.0
7
10
 
@@ -30,7 +30,7 @@ module Attributor
30
30
  self
31
31
  end
32
32
 
33
- def validate( object,context=Attributor::DEFAULT_ROOT_CONTEXT,_attribute)
33
+ def validate( object,context=Attributor::DEFAULT_ROOT_CONTEXT,_attribute=nil)
34
34
  result = []
35
35
  case type
36
36
  when :all
@@ -590,11 +590,9 @@ module Attributor
590
590
  end
591
591
  end
592
592
  end
593
- unless self.class.requirements.empty?
594
- self.class.requirements.each_with_object(ret) do |req, errors|
595
- validation_errors = req.validate( @contents , context)
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
@@ -1,3 +1,3 @@
1
1
  module Attributor
2
- VERSION = '5.0'
2
+ VERSION = '5.0.1'
3
3
  end
@@ -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
 
@@ -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: '5.0'
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-01 00:00:00.000000000 Z
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