285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# File 'lib/attributor/types/hash.rb', line 285
def self.parse(value, context)
if value.nil?
{}
elsif value.is_a?(Attributor::Hash)
value.contents
elsif value.is_a?(::Hash)
value
elsif value.is_a?(::String)
decode_json(value, context)
elsif value.respond_to?(:to_h)
value.to_h
elsif value.respond_to?(:to_hash)
value.to_hash
else
raise Attributor::IncompatibleTypeError.new(context: context, value_type: value.class, type: self)
end
end
|