Module: SerializationHelper::Utils

Defined in:
lib/fidius-common/yamldb/serialization_helper.rb

Class Method Summary collapse

Class Method Details

.boolean_columns(table) ⇒ Object



184
185
186
187
# File 'lib/fidius-common/yamldb/serialization_helper.rb', line 184

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_booleans(records, columns) ⇒ Object



174
175
176
177
178
179
180
181
182
# File 'lib/fidius-common/yamldb/serialization_helper.rb', line 174

def self.convert_booleans(records, columns)
  records.each do |record|
    columns.each do |column|
      next if is_boolean(record[column])
      record[column] = (record[column] == 't' or record[column] == '1')
    end
  end
  records
end

.is_boolean(value) ⇒ Object



189
190
191
# File 'lib/fidius-common/yamldb/serialization_helper.rb', line 189

def self.is_boolean(value)
  value.kind_of?(TrueClass) or value.kind_of?(FalseClass)
end

.quote_table(table) ⇒ Object



193
194
195
# File 'lib/fidius-common/yamldb/serialization_helper.rb', line 193

def self.quote_table(table)
  ActiveRecord::Base.connection.quote_table_name(table)
end

.unhash(hash, keys) ⇒ Object



162
163
164
# File 'lib/fidius-common/yamldb/serialization_helper.rb', line 162

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

.unhash_records(records, keys) ⇒ Object



166
167
168
169
170
171
172
# File 'lib/fidius-common/yamldb/serialization_helper.rb', line 166

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

  records
end