class Forest::Migrations
Attributes
config[R]
engine_name[R]
Public Class Methods
new(config, engine_name)
click to toggle source
Takes the engine config block and engine name
# File lib/forest/migrations.rb, line 9 def initialize(config, engine_name) @config = config @engine_name = engine_name end
Public Instance Methods
check()
click to toggle source
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
# File lib/forest/migrations.rb, line 27 def check if File.directory?(app_dir) engine_in_app = app_migrations.map do |file_name| name, engine = file_name.split('.', 2) next unless match_engine?(engine) name end.compact missing_migrations = engine_migrations.sort - engine_in_app.sort unless missing_migrations.empty? puts "[#{engine_display_name}] ✋ Warning: missing migrations." missing_migrations.each do |migration| puts "[#{engine_display_name}] -- #{migration} from #{engine_name} is missing." end puts "[#{engine_display_name}] -- Run `bundle exec rake railties:install:migrations` to get them.\n\n" true end end end
Private Instance Methods
app_dir()
click to toggle source
# File lib/forest/migrations.rb, line 66 def app_dir "#{Rails.root}/db/migrate" end
app_migrations()
click to toggle source
# File lib/forest/migrations.rb, line 57 def app_migrations Dir.entries(app_dir).map do |file_name| next if migration_file_blacklist.any? { |b| file_name =~ /#{b}/i } next if ['.', '..'].include? file_name name = file_name.split('_', 2).last name.empty? ? next : name end.compact! || [] end
engine_dir()
click to toggle source
# File lib/forest/migrations.rb, line 70 def engine_dir "#{config.root}/db/migrate" end
engine_display_name()
click to toggle source
# File lib/forest/migrations.rb, line 78 def engine_display_name engine_name.capitalize.sub(/_engine/, '') end
engine_migrations()
click to toggle source
# File lib/forest/migrations.rb, line 49 def engine_migrations Dir.entries(engine_dir).map do |file_name| next if migration_file_blacklist.any? { |b| file_name =~ /#{b}/i } name = file_name.split('_', 2).last.split('.', 2).first name.empty? ? next : name end.compact! || [] end
match_engine?(engine)
click to toggle source
# File lib/forest/migrations.rb, line 82 def match_engine?(engine) engine == "#{engine_name}.rb" end
migration_file_blacklist()
click to toggle source
# File lib/forest/migrations.rb, line 74 def migration_file_blacklist ['.DS_STORE'] end