Class: ActiveSchema::TableHub
- Inherits:
-
Object
- Object
- ActiveSchema::TableHub
- Defined in:
- lib/active_schema/table_hub.rb
Instance Attribute Summary collapse
-
#relations ⇒ Object
Returns the value of attribute relations.
-
#tables ⇒ Object
Returns the value of attribute tables.
Instance Method Summary collapse
- #add_foreign_key(from_table_name, to_table_name, column_name) ⇒ Object
- #add_index(table_name, index_def) ⇒ Object
- #add_model(model) ⇒ Object
-
#initialize ⇒ TableHub
constructor
A new instance of TableHub.
Constructor Details
#initialize ⇒ TableHub
Returns a new instance of TableHub.
6 7 8 9 |
# File 'lib/active_schema/table_hub.rb', line 6 def initialize @tables = {} @relations = Hash.new {|h,k| h[k] = Set.new } end |
Instance Attribute Details
#relations ⇒ Object
Returns the value of attribute relations.
5 6 7 |
# File 'lib/active_schema/table_hub.rb', line 5 def relations @relations end |
#tables ⇒ Object
Returns the value of attribute tables.
5 6 7 |
# File 'lib/active_schema/table_hub.rb', line 5 def tables @tables end |
Instance Method Details
#add_foreign_key(from_table_name, to_table_name, column_name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/active_schema/table_hub.rb', line 11 def add_foreign_key(from_table_name, to_table_name, column_name) from_table = find_or_create_table(from_table_name) to_table = find_or_create_table(to_table_name) add_relation(from_table, to_table) from_table.add_foreign_key(column_name, to_table) end |
#add_index(table_name, index_def) ⇒ Object
19 20 21 |
# File 'lib/active_schema/table_hub.rb', line 19 def add_index(table_name, index_def) find_or_create_table(table_name).add_index(index_def) end |
#add_model(model) ⇒ Object
23 24 25 |
# File 'lib/active_schema/table_hub.rb', line 23 def add_model(model) find_or_create_table(model.table_name).model = model end |