Module: YDD::SerializationHelper::Utils
- Defined in:
- lib/ydd/serialization_helper.rb
Class Method Summary collapse
- .boolean?(value) ⇒ Boolean
- .boolean_columns(table) ⇒ Object
- .convert_booleans(records, columns) ⇒ Object
- .quote_table(table) ⇒ Object
- .unhash(hash, keys) ⇒ Object
- .unhash_records(records, keys) ⇒ Object
Class Method Details
.boolean?(value) ⇒ Boolean
105 106 107 |
# File 'lib/ydd/serialization_helper.rb', line 105 def self.boolean?(value) [true, false].include? value end |
.boolean_columns(table) ⇒ Object
100 101 102 103 |
# File 'lib/ydd/serialization_helper.rb', line 100 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
91 92 93 94 95 96 97 98 |
# File 'lib/ydd/serialization_helper.rb', line 91 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
109 110 111 |
# File 'lib/ydd/serialization_helper.rb', line 109 def self.quote_table(table) YDD.connection.quote_table_name(table) end |
.unhash(hash, keys) ⇒ Object
79 80 81 |
# File 'lib/ydd/serialization_helper.rb', line 79 def self.unhash(hash, keys) keys.map { |key| hash[key] } end |
.unhash_records(records, keys) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/ydd/serialization_helper.rb', line 83 def self.unhash_records(records, keys) records.each_with_index do |record, index| records[index] = unhash(record, keys) end records end |