Sha256: 966b44e71a3ff143e4a4eea6acf185ad73b2fab267a46bfc509dfc59e68218d0
Contents?: true
Size: 1.42 KB
Versions: 149
Compression:
Stored size: 1.42 KB
Contents
module Flydata module Heroku module InstanceMethods # @return [Hash] def as_flydata # Logic borrowed from activemodel/lib/active_model/serialization.rb 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 def send_to_flydata $stdout.puts({ self.class.flydata_table_name => as_flydata }.to_json) end end end end
Version data entries
149 entries across 149 versions & 1 rubygems