Sha256: 9fff8c46e3bb9af9eee15441bfc0b667b8f45e6464480dc898a0c9389a27002d

Contents?: true

Size: 364 Bytes

Versions: 5

Compression:

Stored size: 364 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).symbolize_keys
    end
  end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
serial_translator-2.0.5 lib/serial_translator/translation_type.rb
serial_translator-2.0.4 lib/serial_translator/translation_type.rb
serial_translator-2.0.3 lib/serial_translator/translation_type.rb
serial_translator-2.0.2 lib/serial_translator/translation_type.rb
serial_translator-2.0.1 lib/serial_translator/translation_type.rb