Class: Localtower::Generators::ServiceObjects::InsertForeignKeys
- Inherits:
-
Object
- Object
- Localtower::Generators::ServiceObjects::InsertForeignKeys
- Defined in:
- lib/localtower/generators/service_objects/insert_foreign_keys.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(attributes) ⇒ InsertForeignKeys
constructor
A new instance of InsertForeignKeys.
Constructor Details
#initialize(attributes) ⇒ InsertForeignKeys
Returns a new instance of InsertForeignKeys.
5 6 7 |
# File 'lib/localtower/generators/service_objects/insert_foreign_keys.rb', line 5 def initialize(attributes) @attributes = attributes end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/localtower/generators/service_objects/insert_foreign_keys.rb', line 9 def call attributes.each do |attribute| attribute.each do |attr_key, | line_str = Localtower::Tools.line_for_attribute(attr_key)[0] if line_str.present? if ['foreign_key'].present? if line_str['foreign_key: true'] content = File.read(Localtower::Tools.last_migration_pending) else content = File.read(Localtower::Tools.last_migration_pending).gsub(line_str, "#{line_str}, foreign_key: true") end else content = File.read(Localtower::Tools.last_migration_pending).gsub(line_str, line_str.gsub(', foreign_key: true', '')) end File.write(Localtower::Tools.last_migration_pending, content) end end end end |