Class: JewelSeed::Migration
- Inherits:
-
Object
- Object
- JewelSeed::Migration
- Defined in:
- lib/jewel_seed/migration.rb
Instance Attribute Summary collapse
-
#table_names ⇒ Object
readonly
Returns the value of attribute table_names.
Instance Method Summary collapse
- #down ⇒ Object
-
#initialize ⇒ Migration
constructor
A new instance of Migration.
- #seed(*args, **opts) ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize ⇒ Migration
Returns a new instance of Migration.
5 6 7 |
# File 'lib/jewel_seed/migration.rb', line 5 def initialize @table_names = [] end |
Instance Attribute Details
#table_names ⇒ Object (readonly)
Returns the value of attribute table_names.
3 4 5 |
# File 'lib/jewel_seed/migration.rb', line 3 def table_names @table_names end |
Instance Method Details
#down ⇒ Object
25 26 27 |
# File 'lib/jewel_seed/migration.rb', line 25 def down raise NotImplementedError end |
#seed(*args, **opts) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jewel_seed/migration.rb', line 9 def seed(*args, **opts) models = args.first klass = models.first.class table_name = klass.table_name @table_names << table_name puts " - #{klass}" models.each { |model| puts model.inspect } delete_ids = models.map(&:id).uniq.compact klass.delete_all(id: delete_ids) klass.import(*args, opts) end |
#up ⇒ Object
21 22 23 |
# File 'lib/jewel_seed/migration.rb', line 21 def up raise NotImplementedError end |