Class: Appydave::Tools::Types::HashType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/appydave/tools/types/hash_type.rb

Overview

Used by the ActiveModel attributes API to cast values to hashes

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/appydave/tools/types/hash_type.rb', line 8

def cast(value)
  case value
  when String
    JSON.parse(value)
  when Hash
    value
  else
    raise ArgumentError, "Cannot cast #{value.class} to Hash"
  end
end

#serialize(value) ⇒ Object



19
20
21
# File 'lib/appydave/tools/types/hash_type.rb', line 19

def serialize(value)
  value.to_json
end