Sha256: d4f9cc3e3045e5617611669d3fa4c4d730abc4552b1a422b5a23823f377b23ea
Contents?: true
Size: 1.72 KB
Versions: 10
Compression:
Stored size: 1.72 KB
Contents
module Spree class Migrations attr_reader :config, :engine_name # Takes the engine config block and engine name def initialize(config, engine_name) @config, @engine_name = config, engine_name end # 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 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 engine == "#{engine_name}.rb" 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 private def engine_migrations Dir.entries("#{config.root}/db/migrate").map do |file_name| name = file_name.split("_", 2).last.split(".", 2).first name.empty? ? next : name end.compact! || [] end def app_migrations Dir.entries("db/migrate").map do |file_name| next if [".", ".."].include? file_name name = file_name.split("_", 2).last name.empty? ? next : name end.compact! || [] end end end
Version data entries
10 entries across 10 versions & 1 rubygems