Class: MigrExt::RailsApplication
- Inherits:
-
Object
- Object
- MigrExt::RailsApplication
- Defined in:
- lib/migrext/rails.rb
Instance Method Summary collapse
- #create_migration!(version, name, content) ⇒ Object
- #current_migrations ⇒ Object
- #database_version ⇒ Object
- #eval_in_application(code) ⇒ Object
- #external_sources ⇒ Object
- #import_externals! ⇒ Object
-
#initialize(base_dir) ⇒ RailsApplication
constructor
A new instance of RailsApplication.
Constructor Details
#initialize(base_dir) ⇒ RailsApplication
Returns a new instance of RailsApplication.
7 8 9 |
# File 'lib/migrext/rails.rb', line 7 def initialize(base_dir) @base_dir = base_dir end |
Instance Method Details
#create_migration!(version, name, content) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/migrext/rails.rb', line 25 def create_migration!(version, name, content) filename = "#@base_dir/db/migrate/#{version}_#{name.underscore}.rb" raise RuntimeError, "Migration #{version}:#{name} exist" if File.exist?(filename) File.open(filename, "w") {|f| f.write content } @current_migrations = nil end |
#current_migrations ⇒ Object
15 16 17 |
# File 'lib/migrext/rails.rb', line 15 def current_migrations @current_migrations ||= MigrExt::MigrationSet.new(self, nil, "#@base_dir/db/migrate").current_migrations end |
#database_version ⇒ Object
33 34 35 |
# File 'lib/migrext/rails.rb', line 33 def database_version eval_in_application "ActiveRecord::Migrator.current_version" end |
#eval_in_application(code) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/migrext/rails.rb', line 37 def eval_in_application(code) @drb_rails ||= begin require 'drb' rd, wr = IO.pipe @rails_pid = fork do rd.close Dir.chdir @base_dir def eval_code(code); eval code; end require "#{@base_dir}/config/environment.rb" DRb.start_service nil, self wr.print DRb.uri wr.close DRb.thread.join exit 1 # unreachable end wr.close at_exit do begin Process.kill 15, @rails_pid rescue Errno::ESRCH # Process was died some time ago. Ignore the error. true end end DRbObject.new(nil, rd.read) end @drb_rails.eval_code code end |
#external_sources ⇒ Object
19 20 21 22 23 |
# File 'lib/migrext/rails.rb', line 19 def external_sources @external_sources ||= begin eval_in_application("ActiveRecord::Migrator.external_sources") end end |