module SerializationHelper::Utils
Public Class Methods
boolean_columns(table)
click to toggle source
# File lib/serialization_helper.rb, line 129 def self.boolean_columns(table) columns = ActiveRecord::Base.connection.columns(table).reject { |c| silence_warnings { c.type != :boolean } } columns.map { |c| c.name } end
convert_boolean(value)
click to toggle source
# File lib/serialization_helper.rb, line 125 def self.convert_boolean(value) ['t', '1', true, 1].include?(value) end
convert_booleans(records, columns)
click to toggle source
# File lib/serialization_helper.rb, line 115 def self.convert_booleans(records, columns) records.each do |record| columns.each do |column| next if is_boolean(record[column]) record[column] = convert_boolean(record[column]) end end records end
is_boolean(value)
click to toggle source
# File lib/serialization_helper.rb, line 134 def self.is_boolean(value) value.kind_of?(TrueClass) or value.kind_of?(FalseClass) end
quote_table(table)
click to toggle source
# File lib/serialization_helper.rb, line 138 def self.quote_table(table) ActiveRecord::Base.connection.quote_table_name(table) end
unhash(hash, keys)
click to toggle source
# File lib/serialization_helper.rb, line 103 def self.unhash(hash, keys) keys.map { |key| hash[key] } end
unhash_records(records, keys)
click to toggle source
# File lib/serialization_helper.rb, line 107 def self.unhash_records(records, keys) records.each_with_index do |record, index| records[index] = unhash(record, keys) end records end