Class: PgExecArrayParams::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_exec_array_params/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table:, column_name:, as_name:) ⇒ Column

Returns a new instance of Column.



7
8
9
10
11
# File 'lib/pg_exec_array_params/column.rb', line 7

def initialize(table:, column_name:, as_name:)
  @table = table
  @column_name = column_name
  @as_name = as_name
end

Instance Attribute Details

#as_nameObject (readonly)

Returns the value of attribute as_name.



5
6
7
# File 'lib/pg_exec_array_params/column.rb', line 5

def as_name
  @as_name
end

#column_nameObject (readonly)

Returns the value of attribute column_name.



5
6
7
# File 'lib/pg_exec_array_params/column.rb', line 5

def column_name
  @column_name
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/pg_exec_array_params/column.rb', line 5

def table
  @table
end

Class Method Details

.from_res_target(res_target) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pg_exec_array_params/column.rb', line 17

def self.from_res_target(res_target)
  return unless (column_ref = res_target.fetch('val', {})['ColumnRef'])

  idents = column_ref['fields'].map { |field| field.fetch('String', {})['str'] }
  if idents.size <= 1
    column_name = idents.first
  else
    table, column_name, = idents
  end

  return unless column_name

  new(table: table, column_name: column_name, as_name: res_target['name'])
end

Instance Method Details

#nameObject



13
14
15
# File 'lib/pg_exec_array_params/column.rb', line 13

def name
  @as_name || @column_name
end