Module: ArJdbc::SerializedAttributesHelper

Defined in:
lib/arjdbc/jdbc/serialized_attributes_helper.rb

Class Method Summary collapse

Class Method Details

.dump_column_value(record, column) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/arjdbc/jdbc/serialized_attributes_helper.rb', line 4

def self.dump_column_value(record, column)
  value = record[ name = column.name.to_s ]
  if record.class.respond_to?(:serialized_attributes)
    if coder = record.class.serialized_attributes[name]
      value = coder.respond_to?(:dump) ? coder.dump(value) : value.to_yaml
    end
  else
    if record.respond_to?(:unserializable_attribute?)
      value = value.to_yaml if record.unserializable_attribute?(name, column)
    else
      value = value.to_yaml if value.is_a?(Hash)
    end
  end
  value
end