Class: Terrazine::TypeMap
- Inherits:
-
Object
- Object
- Terrazine::TypeMap
- Defined in:
- lib/terrazine/type_map.rb
Overview
PG type map updater
Class Method Summary collapse
- .assign_elements_type(types, parent) ⇒ Object
- .fetch_text_decoder(type) ⇒ Object
- .new_text_decoder(type) ⇒ Object
- .select_text_decoder(type) ⇒ Object
- .update(pg_result, types) ⇒ Object
Class Method Details
.assign_elements_type(types, parent) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/terrazine/type_map.rb', line 30 def assign_elements_type(types, parent) parent.elements_type = if types.count == 1 select_text_decoder(types.shift).new else type = types.shift assign_elements_type(types, select_text_decoder(type)) end parent end |
.fetch_text_decoder(type) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/terrazine/type_map.rb', line 19 def fetch_text_decoder(type) # decoder inside decoder # as example array of arrays with integers - type == [:array, :array, :integer] if type.is_a?(Array) decoder = new_text_decoder type.shift assign_elements_type type, decoder else new_text_decoder type end end |
.new_text_decoder(type) ⇒ Object
40 41 42 |
# File 'lib/terrazine/type_map.rb', line 40 def new_text_decoder(type) select_text_decoder(type).new end |
.select_text_decoder(type) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/terrazine/type_map.rb', line 44 def select_text_decoder(type) decoder = { array: PG::TextDecoder::Array, float: PG::TextDecoder::Float, boolaen: PG::TextDecoder::Boolean, integer: PG::TextDecoder::Integer, date: PG::TextDecoder::TimestampWithoutTimeZone, hstore: Hstore, json: PG::TextDecoder::JSON }[type] raise "Undefined decoder #{type}" unless decoder decoder end |
.update(pg_result, types) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/terrazine/type_map.rb', line 8 def update(pg_result, types) # TODO! why it sometimes column_map? t_m = pg_result.type_map columns_map = t_m.is_a?(PG::TypeMapByColumn) ? t_m : t_m.build_column_map(pg_result) coders = columns_map.coders.dup types.each do |name, type| coders[pg_result.fnumber(name.to_s)] = fetch_text_decoder type end pg_result.type_map = PG::TypeMapByColumn.new coders end |