Module: Toy::Types::JSON

Defined in:
lib/toy/types/json.rb

Class Method Summary collapse

Class Method Details

.from_store(value) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/toy/types/json.rb', line 9

def self.from_store(value, *)
  return value if value.nil?

  if value.is_a?(String)
    ActiveSupport::JSON.decode(value)
  else
    value
  end
end

.to_store(value) ⇒ Object



4
5
6
7
# File 'lib/toy/types/json.rb', line 4

def self.to_store(value, *)
  return value if value.nil?
  ActiveSupport::JSON.encode(value)
end