Class: Reactor::MigrationProxy
- Inherits:
-
Object
- Object
- Reactor::MigrationProxy
- Defined in:
- lib/reactor/tools/migrator.rb
Overview
Class responsible for running a single migration, a helper for Migrator
Instance Method Summary collapse
- #class_name ⇒ Object
- #down ⇒ Object
- #filename ⇒ Object
-
#initialize(versioner, name, version, direction, filename) ⇒ MigrationProxy
constructor
A new instance of MigrationProxy.
- #load_migration ⇒ Object
- #name ⇒ Object
- #run ⇒ Object
- #up ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(versioner, name, version, direction, filename) ⇒ MigrationProxy
Returns a new instance of MigrationProxy.
7 8 9 10 11 12 13 |
# File 'lib/reactor/tools/migrator.rb', line 7 def initialize(versioner, name, version, direction, filename) @versioner = versioner @name = name @version = version @filename = filename @direction = direction end |
Instance Method Details
#class_name ⇒ Object
47 48 49 |
# File 'lib/reactor/tools/migrator.rb', line 47 def class_name return Kernel.const_get(@name) end |
#down ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/reactor/tools/migrator.rb', line 38 def down result = class_name.send(:down) and @versioner.remove(@version) class_name.contained.each do |version| puts "#{class_name.to_s} contains migration #{version}" @versioner.remove(version) end if result result end |
#filename ⇒ Object
59 60 61 |
# File 'lib/reactor/tools/migrator.rb', line 59 def filename @filename end |
#load_migration ⇒ Object
15 16 17 |
# File 'lib/reactor/tools/migrator.rb', line 15 def load_migration load @filename end |
#name ⇒ Object
51 52 53 |
# File 'lib/reactor/tools/migrator.rb', line 51 def name @name end |
#run ⇒ Object
19 20 21 22 |
# File 'lib/reactor/tools/migrator.rb', line 19 def run return down if @direction.to_sym == :down return up end |
#up ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/reactor/tools/migrator.rb', line 24 def up if @versioner.applied?(@version) then puts "Migrating up: #{@name} (#{@filename}) already applied, skipping" return true else result = class_name.send(:up) and @versioner.add(@version) class_name.contained.each do |version| puts "#{class_name.to_s} contains migration #{version}" #@versioner.add(version) # not neccesary! end if result result end end |
#version ⇒ Object
55 56 57 |
# File 'lib/reactor/tools/migrator.rb', line 55 def version @version end |