5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/flydata/heroku/instance_methods.rb', line 5
def as_flydata
options = { :root => nil }
attribute_names = self.class._flydata_attributes || attributes.keys.sort
hash = {}
attribute_names.each do |n|
value = read_attribute_for_serialization(n)
hash[n] = case value
when Time
Flydata.format_time_for_redshift(value)
when DateTime
Flydata.format_time_for_redshift(value)
when Date
Flydata.format_date_for_redshift(value)
else
value
end
end
method_names = Array.wrap(options[:methods]).select { |n| respond_to?(n) }
method_names.each { |n| hash[n] = send(n) }
serializable_add_includes(options) do |association, records, opts|
hash[association] = if records.is_a?(Enumerable)
records.map { |a| a.serializable_hash(opts) }
else
records.serializable_hash(opts)
end
end
hash
end
|