class Blacksand::MyJsonType

为了能使 form 获取对象的状态,因为获取状态是使用 obj.send(name). 而默认 hash 是不能工作的。

Public Instance Methods

deserialize(value) click to toggle source

override active_record 5

Calls superclass method
# File lib/blacksand/my_json_type.rb, line 30
def deserialize(value)
  super_value = super

  if value.is_a?(::String)
    MyOpenStruct.new super_value
  else
    super_value
  end
end
serialize(value) click to toggle source

override active_record 5

Calls superclass method
# File lib/blacksand/my_json_type.rb, line 41
def serialize(value)
  if value.is_a? MyOpenStruct
    ::ActiveSupport::JSON.encode(value.to_h)
  else
    super
  end
end
type_cast_for_database(value) click to toggle source

override active_record 4

Calls superclass method
# File lib/blacksand/my_json_type.rb, line 20
def type_cast_for_database(value)
  if value.is_a? MyOpenStruct
    ::ActiveSupport::JSON.encode(value.to_h)
  else
    super
  end
end
type_cast_from_database(value) click to toggle source

override active_record 4

Calls superclass method
# File lib/blacksand/my_json_type.rb, line 9
def type_cast_from_database(value)
  super_value = super

  if value.is_a?(::String)
    MyOpenStruct.new super_value
  else
    super_value
  end
end