Class: Spree::Migrations

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/migrations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, engine_name) ⇒ Migrations

Takes the engine config block and engine name



8
9
10
# File 'lib/spree/migrations.rb', line 8

def initialize(config, engine_name)
  @config, @engine_name = config, engine_name
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/spree/migrations.rb', line 5

def config
  @config
end

#engine_nameObject (readonly)

Returns the value of attribute engine_name.



5
6
7
# File 'lib/spree/migrations.rb', line 5

def engine_name
  @engine_name
end

Instance Method Details

#checkObject

Puts warning when any engine migration is not present on the Rails app db/migrate dir

First split:

["20131128203548", "update_name_fields_on_spree_credit_cards.spree.rb"]

Second split should give the engine_name of the migration

["update_name_fields_on_spree_credit_cards", "spree.rb"]

Shouldn’t run on test mode because migrations inside engine don’t have engine name on the file name



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spree/migrations.rb', line 25

def check
  if File.directory?(app_dir)
    unless missing_migrations.empty?
      puts "[#{engine_name.capitalize} WARNING] Missing migrations."
      missing_migrations.each do |migration|
        puts "[#{engine_name.capitalize} WARNING] #{migration} from #{engine_name} is missing."
      end
      puts "[#{engine_name.capitalize} WARNING] Run `bundle exec rake railties:install:migrations` to get them.\n\n"
      true
    end
  end
end

#missing_migrationsObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spree/migrations.rb', line 38

def missing_migrations
  @missing_migrations ||=
    begin
      engine_in_app = app_migrations.map do |file_name|
        name, engine = file_name.split(".", 2)
        next unless match_engine?(engine)
        name
      end.compact

      engine_migrations.sort - engine_in_app.sort
    end
end