class HecksAdapters::SQLDatabase::Column

Represents a SQL Column

Attributes

referenced_object[R]

Public Class Methods

factory(attribute) click to toggle source
# File lib/column.rb, line 20
def self.factory(attribute)
  new(
    name: attribute.name,
    referenced_object: attribute.referenced_object,
    type: attribute.type,
    table_name: attribute.object_name,
    is_list: attribute.list?
  )
end
new(name:, referenced_object: nil, table_name: nil, type:, is_list: false) click to toggle source
# File lib/column.rb, line 12
def initialize(name:, referenced_object: nil, table_name: nil, type:, is_list: false)
  @name = name
  @referenced_object = referenced_object
  @type = type
  @table_name = table_name
  @is_list = is_list
end

Public Instance Methods

==(other) click to toggle source
# File lib/column.rb, line 66
def ==(other)
  return false if name != other.name
  return false if referenced_table != other.referenced_table
  true
end
copy(new_attributes={}) click to toggle source
# File lib/column.rb, line 55
def copy(new_attributes={})
  self.class.new(
    {
      name: self.name,
      referenced_object: self.referenced_object,
      type: self.type,
      is_list: self.list?
    }.merge(new_attributes)
  )
end
list?() click to toggle source
# File lib/column.rb, line 38
def list?
  @is_list
end
name() click to toggle source
# File lib/column.rb, line 51
def name
  @name
end
reference?() click to toggle source
# File lib/column.rb, line 42
def reference?
  @referenced_object
end
referenced_table() click to toggle source
# File lib/column.rb, line 46
def referenced_table
  return unless @referenced_object
  @referenced_object.pluralize.underscore
end
to_foreign_key() click to toggle source
# File lib/column.rb, line 30
def to_foreign_key
  (type.downcase + '_id').to_sym
end
to_table_name() click to toggle source
# File lib/column.rb, line 34
def to_table_name
  name.downcase.pluralize.to_sym
end
type() click to toggle source
# File lib/column.rb, line 72
def type
  TYPE_MAP[@type] || @type
end