Class: HoboFields::HabtmModelShim
- Inherits:
-
Struct
- Object
- Struct
- HoboFields::HabtmModelShim
- Defined in:
- lib/hobo_fields/migration_generator.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#foreign_keys ⇒ Object
Returns the value of attribute foreign_keys.
-
#join_table ⇒ Object
Returns the value of attribute join_table.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection
5 6 7 |
# File 'lib/hobo_fields/migration_generator.rb', line 5 def connection @connection end |
#foreign_keys ⇒ Object
Returns the value of attribute foreign_keys
5 6 7 |
# File 'lib/hobo_fields/migration_generator.rb', line 5 def foreign_keys @foreign_keys end |
#join_table ⇒ Object
Returns the value of attribute join_table
5 6 7 |
# File 'lib/hobo_fields/migration_generator.rb', line 5 def join_table @join_table end |
Class Method Details
.from_reflection(refl) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/hobo_fields/migration_generator.rb', line 7 def self.from_reflection(refl) result = self.new result.join_table = refl.[:join_table].to_s result.foreign_keys = [refl.primary_key_name.to_s, refl.association_foreign_key.to_s].sort # this may fail in weird ways if HABTM is running across two DB connections (assuming that's even supported) # figure that anybody who sets THAT up can deal with their own migrations... result.connection = refl.active_record.connection result end |
Instance Method Details
#field_specs ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/hobo_fields/migration_generator.rb', line 21 def field_specs i = 0 foreign_keys.inject({}) do |h, v| # some trickery to avoid an infinite loop when FieldSpec#initialize tries to call model.field_specs h[v] = FieldSpec.new(self, v, :integer, :position => i) i += 1 h end end |
#index_specs ⇒ Object
35 36 37 |
# File 'lib/hobo_fields/migration_generator.rb', line 35 def index_specs [] end |
#primary_key ⇒ Object
31 32 33 |
# File 'lib/hobo_fields/migration_generator.rb', line 31 def primary_key false end |
#table_name ⇒ Object
17 18 19 |
# File 'lib/hobo_fields/migration_generator.rb', line 17 def table_name self.join_table end |