Class: ActiveSchema::Table
- Inherits:
-
Object
- Object
- ActiveSchema::Table
- Defined in:
- lib/active_schema/table.rb
Instance Attribute Summary collapse
-
#foreign_keys ⇒ Object
Returns the value of attribute foreign_keys.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_foreign_key(column, dst_table) ⇒ Object
- #add_index(index) ⇒ Object
-
#initialize(name, model = nil) ⇒ Table
constructor
A new instance of Table.
- #unique_index_on?(column) ⇒ Boolean
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_keys ⇒ Object
Returns the value of attribute foreign_keys.
5 6 7 |
# File 'lib/active_schema/table.rb', line 5 def foreign_keys @foreign_keys end |
#indexes ⇒ Object
Returns the value of attribute indexes.
5 6 7 |
# File 'lib/active_schema/table.rb', line 5 def indexes @indexes end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/active_schema/table.rb', line 5 def model @model end |
#name ⇒ Object
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
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 |