Class: PgGraph::Data::Column

Inherits:
Field show all
Defined in:
lib/pg_graph/data/data.rb

Instance Attribute Summary

Attributes inherited from Field

#record

Attributes inherited from Node

#dimension, #type

Instance Method Summary collapse

Methods inherited from Field

#database, #guid, #name, #to_h, #uid

Methods inherited from DatabaseObject

#<=>, #database, #dot, #guid, #name, #uid

Methods inherited from Node

#data, #object, #to_h, #to_yaml, #value, #value_type

Constructor Details

#initialize(record, name, value) ⇒ Column

Returns a new instance of Column.



469
470
471
472
473
# File 'lib/pg_graph/data/data.rb', line 469

def initialize(record, name, value)
  constrain value, *PgGraph::RUBY_CLASSES
  super(record, name, dimension: 0)
  @impl = value
end

Instance Method Details

#inspectObject



497
# File 'lib/pg_graph/data/data.rb', line 497

def inspect() super value.inspect end

#inspect_innerObject



498
# File 'lib/pg_graph/data/data.rb', line 498

def inspect_inner() "#{name}: #{value.is_a?(String) ? "'#{value}'" : value.inspect}" end

#to_sqlObject

TODO: Escape sequences FIXME: Not in use (and WRONG!)



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/pg_graph/data/data.rb', line 477

def to_sql
  $stderr.puts "* SHOULDN'T BE CALLED IN DATA.RB **************************"
  raise "Oops"
  if value.nil?
    'NULL'
  else
    if type.ruby_class <= Numeric
      value
    elsif type.ruby_class <= Array
      if value.empty?
        "'{}'"
      else
        "'{'#{value.join("', '")}'}"
      end
    else
      "'#{PG::Connection.escape_string(value.to_s)}'"
    end
  end
end