Module: YDD::SerializationHelper::Utils

Defined in:
lib/ydd/serialization_helper.rb

Class Method Summary collapse

Class Method Details

.boolean?(value) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/ydd/serialization_helper.rb', line 148

def self.boolean?(value)
  [true, false].include? value
end

.boolean_columns(table) ⇒ Object



143
144
145
146
# File 'lib/ydd/serialization_helper.rb', line 143

def self.boolean_columns(table)
  columns = YDD.connection.columns(table).reject { |c| silence_warnings { c.type != :boolean } }
  columns.map { |c| c.name }
end

.convert_booleans(records, columns) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/ydd/serialization_helper.rb', line 134

def self.convert_booleans(records, columns)
  records.each do |record|
    columns.each do |column|
      record[column] = ['t', '1', 'true'].include? record[column].to_s
    end
  end
  records
end

.quote_table(table) ⇒ Object



152
153
154
# File 'lib/ydd/serialization_helper.rb', line 152

def self.quote_table(table)
  YDD.connection.quote_table_name(table)
end

.unhash(hash, keys) ⇒ Object



122
123
124
# File 'lib/ydd/serialization_helper.rb', line 122

def self.unhash(hash, keys)
  keys.map { |key| hash[key] }
end

.unhash_records(records, keys) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/ydd/serialization_helper.rb', line 126

def self.unhash_records(records, keys)
  records.each_with_index do |record, index|
    records[index] = unhash(record, keys)
  end

  records
end