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
37
38
# File 'lib/spree/migrations.rb', line 25

def check
  return unless File.directory?(app_dir)
  return if missing_migrations.empty?
  return if ENV['SOLIDUS_SKIP_MIGRATIONS_CHECK']

  prefix = "[WARNING #{engine_name.capitalize}]"
  warn "    \#{prefix} Missing migrations.\n    \#{missing_migrations.map {|m| \"\#{prefix} - \#{m}\"}.join(\"\\n\")}\n    \#{prefix}\n    \#{prefix} Run `bin/rails railties:install:migrations` to get them.\n    \#{prefix} You can silence this warning by setting the `SOLIDUS_SKIP_MIGRATIONS_CHECK` environment variable.\n  WARN\nend\n"

#missing_migrationsObject



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

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