Sha256: 2b53d606a44e6773e377f308267b97f9c890156613bf475eb714f59640c52b02

Contents?: true

Size: 349 Bytes

Versions: 1

Compression:

Stored size: 349 Bytes

Contents

class SerialTranslator::TranslationType < ActiveRecord::Type::String
  def cast(value)
    case value
    when nil
      {}
    when Hash
      value
    when /\A---/
      YAML.load(value)
    else
      JSON.parse(value)
    end
  end

  def serialize(value)
    case value
    when String
      super
    else
      JSON(value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
serial_translator-2.0.0 lib/serial_translator/translation_type.rb