Module: EngineMigrationInitializer

Defined in:
lib/engine_migration_initializer.rb,
lib/engine_migration_initializer/version.rb

Overview

‘extend` your engine’s engine.rb with this module to have your host app load your engine’s migrations

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/engine_migration_initializer.rb', line 6

def self.extended(base)
  base.initializer :append_migrations do |app|
    case Rails::VERSION::MAJOR
    when 3
      unless app.root.to_s.match root.to_s
        app.config.paths["db/migrate"] += config.paths["db/migrate"].expanded
      end
    else # Tested w/ Rails 4
      begin
        unless app.root.to_s.match root.to_s
          config.paths["db/migrate"].expanded.each do |expanded_path|
            app.config.paths["db/migrate"] << expanded_path
          end
        end
      rescue => e
        raise "EngineMigrationInitializer did not know how to append_migrations for Rails v#{Rails::VERSION::MAJOR}\nError was: #{e.class} #{e.message}"
      end
    end
  end
end