Class: Spree::Migrations

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Migrations) initialize(config, engine_name)

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

- (Object) config (readonly)

Returns the value of attribute config



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

def config
  @config
end

- (Object) engine_name (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

- (Object) check

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

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

- (Object) missing_migrations



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

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