Class: JewelSeed::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/jewel_seed/migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMigration

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_namesObject (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

#downObject

Raises:

  • (NotImplementedError)


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

#upObject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/jewel_seed/migration.rb', line 21

def up
  raise NotImplementedError
end