attributor 5.0.2 → 5.1.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/.rubocop.yml +30 -0
- data/.travis.yml +6 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile +1 -1
- data/Guardfile +14 -8
- data/Rakefile +4 -5
- data/attributor.gemspec +34 -29
- data/lib/attributor.rb +23 -29
- data/lib/attributor/attribute.rb +108 -127
- data/lib/attributor/attribute_resolver.rb +12 -26
- data/lib/attributor/dsl_compiler.rb +17 -21
- data/lib/attributor/dumpable.rb +1 -2
- data/lib/attributor/example_mixin.rb +5 -8
- data/lib/attributor/exceptions.rb +5 -6
- data/lib/attributor/extensions/randexp.rb +3 -5
- data/lib/attributor/extras/field_selector.rb +4 -4
- data/lib/attributor/extras/field_selector/transformer.rb +6 -7
- data/lib/attributor/families/numeric.rb +0 -2
- data/lib/attributor/families/temporal.rb +1 -4
- data/lib/attributor/hash_dsl_compiler.rb +22 -25
- data/lib/attributor/type.rb +24 -32
- data/lib/attributor/types/bigdecimal.rb +7 -14
- data/lib/attributor/types/boolean.rb +5 -8
- data/lib/attributor/types/class.rb +9 -10
- data/lib/attributor/types/collection.rb +34 -44
- data/lib/attributor/types/container.rb +9 -15
- data/lib/attributor/types/csv.rb +7 -10
- data/lib/attributor/types/date.rb +20 -25
- data/lib/attributor/types/date_time.rb +7 -14
- data/lib/attributor/types/float.rb +4 -6
- data/lib/attributor/types/hash.rb +171 -196
- data/lib/attributor/types/ids.rb +2 -6
- data/lib/attributor/types/integer.rb +12 -17
- data/lib/attributor/types/model.rb +39 -48
- data/lib/attributor/types/object.rb +2 -4
- data/lib/attributor/types/polymorphic.rb +118 -0
- data/lib/attributor/types/regexp.rb +4 -5
- data/lib/attributor/types/string.rb +6 -7
- data/lib/attributor/types/struct.rb +8 -15
- data/lib/attributor/types/symbol.rb +3 -6
- data/lib/attributor/types/tempfile.rb +5 -6
- data/lib/attributor/types/time.rb +11 -11
- data/lib/attributor/types/uri.rb +9 -10
- data/lib/attributor/version.rb +1 -1
- data/spec/attribute_resolver_spec.rb +57 -78
- data/spec/attribute_spec.rb +174 -216
- data/spec/attributor_spec.rb +11 -15
- data/spec/dsl_compiler_spec.rb +19 -33
- data/spec/dumpable_spec.rb +6 -7
- data/spec/extras/field_selector/field_selector_spec.rb +1 -1
- data/spec/families_spec.rb +1 -3
- data/spec/hash_dsl_compiler_spec.rb +65 -74
- data/spec/spec_helper.rb +9 -3
- data/spec/support/hashes.rb +2 -3
- data/spec/support/models.rb +30 -36
- data/spec/support/polymorphics.rb +10 -0
- data/spec/type_spec.rb +38 -61
- data/spec/types/bigdecimal_spec.rb +11 -15
- data/spec/types/boolean_spec.rb +12 -39
- data/spec/types/class_spec.rb +10 -11
- data/spec/types/collection_spec.rb +72 -81
- data/spec/types/container_spec.rb +22 -26
- data/spec/types/csv_spec.rb +15 -16
- data/spec/types/date_spec.rb +16 -33
- data/spec/types/date_time_spec.rb +16 -33
- data/spec/types/file_upload_spec.rb +1 -2
- data/spec/types/float_spec.rb +7 -14
- data/spec/types/hash_spec.rb +285 -289
- data/spec/types/ids_spec.rb +5 -7
- data/spec/types/integer_spec.rb +37 -46
- data/spec/types/model_spec.rb +111 -128
- data/spec/types/polymorphic_spec.rb +134 -0
- data/spec/types/regexp_spec.rb +4 -7
- data/spec/types/string_spec.rb +17 -21
- data/spec/types/struct_spec.rb +40 -47
- data/spec/types/tempfile_spec.rb +1 -2
- data/spec/types/temporal_spec.rb +9 -0
- data/spec/types/time_spec.rb +16 -32
- data/spec/types/type_spec.rb +15 -0
- data/spec/types/uri_spec.rb +6 -7
- metadata +77 -25
data/spec/types/tempfile_spec.rb
CHANGED
data/spec/types/time_spec.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
2
|
|
3
3
|
describe Attributor::Time do
|
4
|
-
|
5
4
|
subject(:type) { Attributor::Time }
|
6
5
|
|
7
6
|
it 'it is not Dumpable' do
|
8
|
-
type.new.is_a?(Attributor::Dumpable).
|
7
|
+
expect(type.new.is_a?(Attributor::Dumpable)).not_to be(true)
|
9
8
|
end
|
10
9
|
|
11
10
|
context '.native_type' do
|
@@ -17,45 +16,40 @@ describe Attributor::Time do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
context '.dump' do
|
20
|
-
let(:example) { type.example}
|
19
|
+
let(:example) { type.example }
|
21
20
|
subject(:value) { type.dump(example) }
|
22
21
|
it 'is formatted correctly' do
|
23
|
-
value.
|
22
|
+
expect(value).to match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+-]\d{2}:\d{2}/)
|
24
23
|
end
|
25
24
|
context 'nil values' do
|
26
25
|
it 'should be nil' do
|
27
|
-
type.dump(nil).
|
26
|
+
expect(type.dump(nil)).to be_nil
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
31
|
context '.load' do
|
34
|
-
|
35
32
|
it 'returns nil for nil' do
|
36
|
-
type.load(nil).
|
33
|
+
expect(type.load(nil)).to be(nil)
|
37
34
|
end
|
38
35
|
|
39
36
|
context 'for incoming objects' do
|
40
|
-
|
41
|
-
it "returns correct Time for DateTime objects" do
|
37
|
+
it 'returns correct Time for DateTime objects' do
|
42
38
|
object = Time.now
|
43
39
|
loaded = type.load(object)
|
44
|
-
loaded.
|
45
|
-
loaded.to_time.
|
40
|
+
expect(loaded).to be_a(::Time)
|
41
|
+
expect(loaded.to_time).to eq object
|
46
42
|
end
|
47
43
|
|
48
|
-
it
|
44
|
+
it 'returns correct Time for DateTime objects' do
|
49
45
|
object = DateTime.now
|
50
46
|
loaded = type.load(object)
|
51
|
-
loaded.
|
52
|
-
loaded.
|
47
|
+
expect(loaded).to be_a(::Time)
|
48
|
+
expect(loaded).to eq(object.to_time)
|
53
49
|
end
|
54
|
-
|
55
50
|
end
|
56
51
|
|
57
52
|
context 'for incoming strings' do
|
58
|
-
|
59
53
|
[
|
60
54
|
'2001-02-03T04:05:06+07:00',
|
61
55
|
'Sat, 03 Feb 2001 04:05:06 GMT',
|
@@ -67,11 +61,9 @@ describe Attributor::Time do
|
|
67
61
|
'2007-10-19T04:11:33Z',
|
68
62
|
'2001-02-03T04:05:06+07:00.123456', # custom format with microseconds
|
69
63
|
].each do |value|
|
70
|
-
|
71
64
|
it "returns correct Time for #{value.inspect}" do
|
72
|
-
type.load(value).
|
65
|
+
expect(type.load(value)).to eq Time.parse(value)
|
73
66
|
end
|
74
|
-
|
75
67
|
end
|
76
68
|
|
77
69
|
[
|
@@ -79,31 +71,23 @@ describe Attributor::Time do
|
|
79
71
|
'2007-10-33T04:11:33Z',
|
80
72
|
'2001-02-33T04:05:06+07:00.123456', # custom format with microseconds
|
81
73
|
].each do |value|
|
82
|
-
|
83
74
|
it "raises Attributor::AttributorException for #{value.inspect}" do
|
84
|
-
expect
|
75
|
+
expect do
|
85
76
|
type.load(value)
|
86
|
-
|
77
|
+
end.to raise_error(Attributor::DeserializationError, /Error deserializing a String using Time/)
|
87
78
|
end
|
88
|
-
|
89
79
|
end
|
90
80
|
|
91
81
|
[
|
92
82
|
'',
|
93
83
|
'foobar'
|
94
84
|
].each do |value|
|
95
|
-
|
96
85
|
it "raises Attributor::AttributorException for #{value.inspect}" do
|
97
|
-
expect
|
86
|
+
expect do
|
98
87
|
type.load(value)
|
99
|
-
|
88
|
+
end.to raise_error(Attributor::DeserializationError, /Error deserializing a String using Time/)
|
100
89
|
end
|
101
|
-
|
102
90
|
end
|
103
|
-
|
104
91
|
end
|
105
|
-
|
106
92
|
end
|
107
|
-
|
108
93
|
end
|
109
|
-
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Attributor::Type do
|
4
|
+
subject(:type) do
|
5
|
+
Class.new { include Attributor::Type }
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'raises an error for unimplemented example' do
|
9
|
+
expect { type.example }.to raise_error(Attributor::AttributorException)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'raises an error for unimplemented valid_type?' do
|
13
|
+
expect { type.valid_type?('foo') }.to raise_error(Attributor::AttributorException)
|
14
|
+
end
|
15
|
+
end
|
data/spec/types/uri_spec.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
2
|
|
3
3
|
describe Attributor::URI do
|
4
|
-
|
5
4
|
subject(:type) { Attributor::URI }
|
6
5
|
|
7
6
|
it 'it is not Dumpable' do
|
8
|
-
type.new.is_a?(Attributor::Dumpable).
|
7
|
+
expect(type.new.is_a?(Attributor::Dumpable)).not_to be(true)
|
9
8
|
end
|
10
9
|
|
11
10
|
its(:native_type) { should be ::URI::Generic }
|
@@ -17,7 +16,7 @@ describe Attributor::URI do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
context '.dump' do
|
20
|
-
let(:example){ type.example }
|
19
|
+
let(:example) { type.example }
|
21
20
|
it 'uses the underlying URI to_s' do
|
22
21
|
expect(type.dump(example)).to eq(example.to_s)
|
23
22
|
end
|
@@ -65,7 +64,7 @@ describe Attributor::URI do
|
|
65
64
|
end
|
66
65
|
|
67
66
|
context 'when given a path option' do
|
68
|
-
let(:attribute) { Attributor::Attribute.new(type, path:
|
67
|
+
let(:attribute) { Attributor::Attribute.new(type, path: %r{^/}) }
|
69
68
|
|
70
69
|
context 'given a URI that matches the path regex' do
|
71
70
|
it 'does not return any errors' do
|
@@ -89,14 +88,14 @@ describe Attributor::URI do
|
|
89
88
|
|
90
89
|
context 'for path option' do
|
91
90
|
context 'given a regex definition' do
|
92
|
-
let(:options) { {path: Regexp.new('a-z')} }
|
91
|
+
let(:options) { { path: Regexp.new('a-z') } }
|
93
92
|
it 'checks successfully' do
|
94
93
|
expect(subject).to be_kind_of(Attributor::Attribute)
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
97
|
context 'given any definition other than regex' do
|
99
|
-
let(:options) { {path: 1} }
|
98
|
+
let(:options) { { path: 1 } }
|
100
99
|
it 'raises an exception' do
|
101
100
|
expect { subject }.to raise_error(Attributor::AttributorException)
|
102
101
|
end
|
@@ -104,7 +103,7 @@ describe Attributor::URI do
|
|
104
103
|
end
|
105
104
|
|
106
105
|
context 'for any other option' do
|
107
|
-
let(:options) { {something: 1} }
|
106
|
+
let(:options) { { something: 1 } }
|
108
107
|
it 'raises an exception' do
|
109
108
|
expect { subject }.to raise_error(Attributor::AttributorException)
|
110
109
|
end
|
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.1.0
|
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: 2016-
|
12
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -57,72 +57,86 @@ dependencies:
|
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '3'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '3'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: rspec-its
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec-collection_matchers
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
73
87
|
requirements:
|
74
88
|
- - "~>"
|
75
89
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
90
|
+
version: '1'
|
77
91
|
type: :development
|
78
92
|
prerelease: false
|
79
93
|
version_requirements: !ruby/object:Gem::Requirement
|
80
94
|
requirements:
|
81
95
|
- - "~>"
|
82
96
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
97
|
+
version: '1'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
99
|
+
name: yard
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
87
101
|
requirements:
|
88
102
|
- - "~>"
|
89
103
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
104
|
+
version: 0.8.7
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
109
|
- - "~>"
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
111
|
+
version: 0.8.7
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
113
|
+
name: backports
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
116
|
- - "~>"
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
118
|
+
version: '3'
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
123
|
- - "~>"
|
110
124
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
125
|
+
version: '3'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
127
|
+
name: yardstick
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
|
-
- - "
|
130
|
+
- - "~>"
|
117
131
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
132
|
+
version: '0'
|
119
133
|
type: :development
|
120
134
|
prerelease: false
|
121
135
|
version_requirements: !ruby/object:Gem::Requirement
|
122
136
|
requirements:
|
123
|
-
- - "
|
137
|
+
- - "~>"
|
124
138
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
139
|
+
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: bundler
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -239,16 +253,44 @@ dependencies:
|
|
239
253
|
name: fuubar
|
240
254
|
requirement: !ruby/object:Gem::Requirement
|
241
255
|
requirements:
|
242
|
-
- - "
|
256
|
+
- - ">="
|
243
257
|
- !ruby/object:Gem::Version
|
244
|
-
version: '
|
258
|
+
version: '0'
|
245
259
|
type: :development
|
246
260
|
prerelease: false
|
247
261
|
version_requirements: !ruby/object:Gem::Requirement
|
248
262
|
requirements:
|
249
|
-
- - "
|
263
|
+
- - ">="
|
250
264
|
- !ruby/object:Gem::Version
|
251
|
-
version: '
|
265
|
+
version: '0'
|
266
|
+
- !ruby/object:Gem::Dependency
|
267
|
+
name: rubocop
|
268
|
+
requirement: !ruby/object:Gem::Requirement
|
269
|
+
requirements:
|
270
|
+
- - ">="
|
271
|
+
- !ruby/object:Gem::Version
|
272
|
+
version: '0'
|
273
|
+
type: :development
|
274
|
+
prerelease: false
|
275
|
+
version_requirements: !ruby/object:Gem::Requirement
|
276
|
+
requirements:
|
277
|
+
- - ">="
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: '0'
|
280
|
+
- !ruby/object:Gem::Dependency
|
281
|
+
name: guard-rubocop
|
282
|
+
requirement: !ruby/object:Gem::Requirement
|
283
|
+
requirements:
|
284
|
+
- - ">="
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: '0'
|
287
|
+
type: :development
|
288
|
+
prerelease: false
|
289
|
+
version_requirements: !ruby/object:Gem::Requirement
|
290
|
+
requirements:
|
291
|
+
- - ">="
|
292
|
+
- !ruby/object:Gem::Version
|
293
|
+
version: '0'
|
252
294
|
- !ruby/object:Gem::Dependency
|
253
295
|
name: parslet
|
254
296
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,6 +315,7 @@ extra_rdoc_files: []
|
|
273
315
|
files:
|
274
316
|
- ".gitignore"
|
275
317
|
- ".rspec"
|
318
|
+
- ".rubocop.yml"
|
276
319
|
- ".travis.yml"
|
277
320
|
- CHANGELOG.md
|
278
321
|
- Gemfile
|
@@ -311,6 +354,7 @@ files:
|
|
311
354
|
- lib/attributor/types/integer.rb
|
312
355
|
- lib/attributor/types/model.rb
|
313
356
|
- lib/attributor/types/object.rb
|
357
|
+
- lib/attributor/types/polymorphic.rb
|
314
358
|
- lib/attributor/types/regexp.rb
|
315
359
|
- lib/attributor/types/string.rb
|
316
360
|
- lib/attributor/types/struct.rb
|
@@ -330,6 +374,7 @@ files:
|
|
330
374
|
- spec/spec_helper.rb
|
331
375
|
- spec/support/hashes.rb
|
332
376
|
- spec/support/models.rb
|
377
|
+
- spec/support/polymorphics.rb
|
333
378
|
- spec/type_spec.rb
|
334
379
|
- spec/types/bigdecimal_spec.rb
|
335
380
|
- spec/types/boolean_spec.rb
|
@@ -345,11 +390,14 @@ files:
|
|
345
390
|
- spec/types/ids_spec.rb
|
346
391
|
- spec/types/integer_spec.rb
|
347
392
|
- spec/types/model_spec.rb
|
393
|
+
- spec/types/polymorphic_spec.rb
|
348
394
|
- spec/types/regexp_spec.rb
|
349
395
|
- spec/types/string_spec.rb
|
350
396
|
- spec/types/struct_spec.rb
|
351
397
|
- spec/types/tempfile_spec.rb
|
398
|
+
- spec/types/temporal_spec.rb
|
352
399
|
- spec/types/time_spec.rb
|
400
|
+
- spec/types/type_spec.rb
|
353
401
|
- spec/types/uri_spec.rb
|
354
402
|
homepage: https://github.com/rightscale/attributor
|
355
403
|
licenses:
|
@@ -371,7 +419,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
371
419
|
version: '0'
|
372
420
|
requirements: []
|
373
421
|
rubyforge_project:
|
374
|
-
rubygems_version: 2.
|
422
|
+
rubygems_version: 2.5.1
|
375
423
|
signing_key:
|
376
424
|
specification_version: 4
|
377
425
|
summary: A powerful attribute and type management library for Ruby
|
@@ -387,6 +435,7 @@ test_files:
|
|
387
435
|
- spec/spec_helper.rb
|
388
436
|
- spec/support/hashes.rb
|
389
437
|
- spec/support/models.rb
|
438
|
+
- spec/support/polymorphics.rb
|
390
439
|
- spec/type_spec.rb
|
391
440
|
- spec/types/bigdecimal_spec.rb
|
392
441
|
- spec/types/boolean_spec.rb
|
@@ -402,10 +451,13 @@ test_files:
|
|
402
451
|
- spec/types/ids_spec.rb
|
403
452
|
- spec/types/integer_spec.rb
|
404
453
|
- spec/types/model_spec.rb
|
454
|
+
- spec/types/polymorphic_spec.rb
|
405
455
|
- spec/types/regexp_spec.rb
|
406
456
|
- spec/types/string_spec.rb
|
407
457
|
- spec/types/struct_spec.rb
|
408
458
|
- spec/types/tempfile_spec.rb
|
459
|
+
- spec/types/temporal_spec.rb
|
409
460
|
- spec/types/time_spec.rb
|
461
|
+
- spec/types/type_spec.rb
|
410
462
|
- spec/types/uri_spec.rb
|
411
463
|
has_rdoc:
|