Class: ActiveRecord::ConnectionAdapters::Redshift::OID::Json

Inherits:
Type::Value
  • Object
show all
Includes:
ActiveModel::Type::Helpers::Mutable
Defined in:
lib/active_record/connection_adapters/redshift/oid/json.rb

Overview

:nodoc:

Direct Known Subclasses

Jsonb

Instance Method Summary collapse

Instance Method Details

#accessorObject



28
29
30
# File 'lib/active_record/connection_adapters/redshift/oid/json.rb', line 28

def accessor
  ActiveRecord::Store::StringKeyedHashAccessor
end

#typeObject



8
9
10
# File 'lib/active_record/connection_adapters/redshift/oid/json.rb', line 8

def type
  :json
end

#type_cast_for_database(value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/active_record/connection_adapters/redshift/oid/json.rb', line 20

def type_cast_for_database(value)
  if value.is_a?(::Array) || value.is_a?(::Hash)
    ::ActiveSupport::JSON.encode(value)
  else
    super
  end
end

#type_cast_from_database(value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/active_record/connection_adapters/redshift/oid/json.rb', line 12

def type_cast_from_database(value)
  if value.is_a?(::String)
    ::ActiveSupport::JSON.decode(value) rescue nil
  else
    super
  end
end