Class: Hecks::Adapters::SQLDatabase::Table

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, columns:) ⇒ Table

Returns a new instance of Table.



18
19
20
21
# File 'lib/table.rb', line 18

def initialize(name:, columns:)
  @name = name
  @columns = columns
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



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

def columns
  @columns
end

Class Method Details

.factory(domain_objects) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/table.rb', line 7

def self.factory(domain_objects)
  r = domain_objects.map do |domain_object|
    new(
      name: domain_object.name,
      columns: domain_object.attributes.map do |attribute|
        Column.factory(attribute)
      end
    )
  end
end

Instance Method Details

#foreign_key_columnsObject



31
32
33
# File 'lib/table.rb', line 31

def foreign_key_columns
  columns.select(&:reference?)
end

#join_table_columnsObject



27
28
29
# File 'lib/table.rb', line 27

def join_table_columns
  columns.select(&:list?)
end

#nameObject



35
36
37
# File 'lib/table.rb', line 35

def name
  @name.pluralize.underscore
end

#to_foreign_keyObject



23
24
25
# File 'lib/table.rb', line 23

def to_foreign_key
  (name.singularize + '_id').to_sym
end