attributor 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/attributor/types/hash.rb +1 -2
- data/lib/attributor/types/model.rb +7 -4
- data/lib/attributor/version.rb +1 -1
- data/spec/types/hash_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76667cd055dc19dfec12646bbdbf1514c90f71d9
|
4
|
+
data.tar.gz: 828783ff925e1a52b46fba2b2bd63c658f0cb6b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa70abf93838a54751afb73020cd949ce7aa829fd6d9c679e84d8326d5b93fb2a06275b121b59a7495159b9ae40d5fdfce3d5c81d7b17c0a170eba42d9b3b66
|
7
|
+
data.tar.gz: 862d52a9800f01e7dd853b2b331a1e9edda95f26634ac50907e658b4cca510888f034fc8e0c69d8bca60c4b857ae3be8ac73976476a6c3e09e2c8ad6dfaa4571
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,14 @@ Attributor Changelog
|
|
4
4
|
next
|
5
5
|
------
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
2.2.1
|
9
|
+
------
|
10
|
+
|
11
|
+
* Dumping attributes will now load the values if they're not in the native type.
|
12
|
+
* `Model.valid_type?` now accepts hashes.
|
13
|
+
* `Hash`:
|
14
|
+
* Added `:has_key?` to delegation
|
8
15
|
|
9
16
|
2.2.0
|
10
17
|
------
|
@@ -159,7 +159,6 @@ module Attributor
|
|
159
159
|
|
160
160
|
def self.dump(value, **opts)
|
161
161
|
return nil if value.nil?
|
162
|
-
return super if (@key_type == Object && @value_type == Object )
|
163
162
|
|
164
163
|
value.each_with_object({}) do |(k,v),hash|
|
165
164
|
k = key_type.dump(k,opts) if @key_type
|
@@ -309,7 +308,7 @@ module Attributor
|
|
309
308
|
# TODO: add a validate, which simply validates that the incoming keys and values are of the right type.
|
310
309
|
# Think about the format of the subcontexts to use: let's use .at(key.to_s)
|
311
310
|
attr_reader :contents
|
312
|
-
def_delegators :@contents, :[], :[]=, :each, :size, :keys, :key?, :values, :empty?
|
311
|
+
def_delegators :@contents, :[], :[]=, :each, :size, :keys, :key?, :values, :empty?, :has_key?
|
313
312
|
|
314
313
|
def initialize(contents={})
|
315
314
|
@contents = contents
|
@@ -117,7 +117,7 @@ module Attributor
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def self.dump(value, **opts)
|
120
|
-
value.dump(opts)
|
120
|
+
self.load(value).dump(**opts)
|
121
121
|
end
|
122
122
|
|
123
123
|
def self.native_type
|
@@ -209,6 +209,9 @@ module Attributor
|
|
209
209
|
object.validate(context)
|
210
210
|
end
|
211
211
|
|
212
|
+
def self.valid_type?(type)
|
213
|
+
type.kind_of?(self) || type.kind_of?(::Hash)
|
214
|
+
end
|
212
215
|
|
213
216
|
def self.dsl_class
|
214
217
|
@options[:dsl_compiler] || DSLCompiler
|
@@ -255,7 +258,7 @@ module Attributor
|
|
255
258
|
self.class.attributes.each_with_object(Array.new) do |(sub_attribute_name, sub_attribute), errors|
|
256
259
|
sub_context = self.class.generate_subcontext(context,sub_attribute_name)
|
257
260
|
|
258
|
-
value = self.
|
261
|
+
value = self.__send__(sub_attribute_name)
|
259
262
|
if value.respond_to?(:validating) # really, it's a thing with sub-attributes
|
260
263
|
next if value.validating
|
261
264
|
end
|
@@ -269,7 +272,7 @@ module Attributor
|
|
269
272
|
|
270
273
|
def attributes
|
271
274
|
@lazy_attributes.keys.each do |name|
|
272
|
-
self.
|
275
|
+
self.__send__(name)
|
273
276
|
end
|
274
277
|
@attributes
|
275
278
|
end
|
@@ -291,7 +294,7 @@ module Attributor
|
|
291
294
|
|
292
295
|
if self.class.attributes.has_key?(attribute_name.to_sym)
|
293
296
|
self.class.define_accessors(attribute_name)
|
294
|
-
return self.
|
297
|
+
return self.__send__(name, *args)
|
295
298
|
end
|
296
299
|
|
297
300
|
super
|
data/lib/attributor/version.rb
CHANGED
data/spec/types/hash_spec.rb
CHANGED
@@ -395,6 +395,16 @@ describe Attributor::Hash do
|
|
395
395
|
end
|
396
396
|
|
397
397
|
end
|
398
|
+
context 'will always return a top level hash' do
|
399
|
+
subject(:type_dump){ type.dump(value) }
|
400
|
+
let(:key_type){ Attributor::Object }
|
401
|
+
let(:value_type){ Attributor::Object }
|
402
|
+
|
403
|
+
it 'even when key/types are object' do
|
404
|
+
subject.should be_kind_of(::Hash)
|
405
|
+
subject.should eq( hash )
|
406
|
+
end
|
407
|
+
end
|
398
408
|
end
|
399
409
|
|
400
410
|
context 'with case_insensitive_load option for string keys' do
|