Method: Attributor::Hash.parse

Defined in:
lib/attributor/types/hash.rb

.parse(value, context) ⇒ Object



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) # Deprecate this in lieu of to_h only?
    value.to_hash
  else
    raise Attributor::IncompatibleTypeError.new(context: context, value_type: value.class, type: self)
  end
end