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



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

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/spree/migrations.rb', line 3

def config
  @config
end

#engine_nameObject (readonly)

Returns the value of attribute engine_name.



3
4
5
# File 'lib/spree/migrations.rb', line 3

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



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

def check
  if File.exists?("config/spree.yml") && File.directory?("db/migrate")
    engine_in_app = app_migrations.map do |file_name|
      name, engine = file_name.split(".", 2)
      next unless match_engine?(engine)
      name
    end.compact! || []

    unless (engine_migrations.sort - engine_in_app.sort).empty?
      puts "[#{engine_name.capitalize} WARNING] Missing migrations." \
           " Run `bundle exec rake railties:install:migrations` to get them.\n\n"
      true
    end
  end
end