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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93e65f034891a43eb2164a43a0bd5bdf7d2a0e22
4
- data.tar.gz: dc626f0b5d2cb575f490a1e1d8af6c60d232830f
3
+ metadata.gz: 76667cd055dc19dfec12646bbdbf1514c90f71d9
4
+ data.tar.gz: 828783ff925e1a52b46fba2b2bd63c658f0cb6b6
5
5
  SHA512:
6
- metadata.gz: 514f798b6bcb84313fa6c840dcb0a4bf9533cb3ec7f29a1c9a8ca00db45d119e7122a2bea02289fe094a6ab8db41ff13af0bfb47fafe9568186243f44d25b3f6
7
- data.tar.gz: 848e54a8cdf56ab1a498ea75fbddc3571c7723a1285cc8b8c1085a2fa55e6b0a75494968c83f8154bab58f04531a684ea05114970e83c45b53a7c10e6e6a2883
6
+ metadata.gz: 8aa70abf93838a54751afb73020cd949ce7aa829fd6d9c679e84d8326d5b93fb2a06275b121b59a7495159b9ae40d5fdfce3d5c81d7b17c0a170eba42d9b3b66
7
+ data.tar.gz: 862d52a9800f01e7dd853b2b331a1e9edda95f26634ac50907e658b4cca510888f034fc8e0c69d8bca60c4b857ae3be8ac73976476a6c3e09e2c8ad6dfaa4571
@@ -4,7 +4,14 @@ Attributor Changelog
4
4
  next
5
5
  ------
6
6
 
7
- * next thing here
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.send(sub_attribute_name)
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.send(name)
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.send(name, *args)
297
+ return self.__send__(name, *args)
295
298
  end
296
299
 
297
300
  super
@@ -1,3 +1,3 @@
1
1
  module Attributor
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -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
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: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer