Class: ActiveSchema::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, model = nil) ⇒ Table

Returns a new instance of Table.



6
7
8
9
10
11
# File 'lib/active_schema/table.rb', line 6

def initialize(name, model = nil)
  @name  = name
  @model = model
  @foreign_keys = {}
  @indexes = []
end

Instance Attribute Details

#foreign_keysObject

Returns the value of attribute foreign_keys.



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

def foreign_keys
  @foreign_keys
end

#indexesObject

Returns the value of attribute indexes.



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

def indexes
  @indexes
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#add_foreign_key(column, dst_table) ⇒ Object



13
14
15
# File 'lib/active_schema/table.rb', line 13

def add_foreign_key(column, dst_table)
  @foreign_keys[column] = dst_table
end

#add_index(index) ⇒ Object



17
18
19
# File 'lib/active_schema/table.rb', line 17

def add_index(index)
  @indexes << index
end

#unique_index_on?(column) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/active_schema/table.rb', line 21

def unique_index_on?(column)
  @indexes.any? do |idx|
    idx.columns.size == 1 &&
      idx.columns.first == column &&
      idx.unique
  end
end