Class: Spree::Migrations
- Inherits:
-
Object
- Object
- Spree::Migrations
- Defined in:
- lib/spree/migrations.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#engine_name ⇒ Object
readonly
Returns the value of attribute engine_name.
Instance Method Summary collapse
-
#check ⇒ Object
Puts warning when any engine migration is not present on the Rails app db/migrate dir.
-
#initialize(config, engine_name) ⇒ Migrations
constructor
Takes the engine config block and engine name.
- #missing_migrations ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/spree/migrations.rb', line 5 def config @config end |
#engine_name ⇒ Object (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
#check ⇒ Object
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 <<~WARN #{prefix} Missing migrations. #{missing_migrations.map {|m| "#{prefix} - #{m}"}.join("\n")} #{prefix} #{prefix} Run `bin/rails railties:install:migrations` to get them. #{prefix} You can silence this warning by setting the `SOLIDUS_SKIP_MIGRATIONS_CHECK` environment variable. WARN end |
#missing_migrations ⇒ Object
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 |