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 Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #class_name ⇒ Object
- #down ⇒ Object
-
#initialize(versioner, name, version, direction, filename) ⇒ MigrationProxy
constructor
A new instance of MigrationProxy.
- #load_migration ⇒ Object
- #run ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(versioner, name, version, direction, filename) ⇒ MigrationProxy
Returns a new instance of MigrationProxy.
6 7 8 9 10 11 12 |
# File 'lib/reactor/tools/migrator.rb', line 6 def initialize(versioner, name, version, direction, filename) @versioner = versioner @name = name @version = version @filename = filename @direction = direction end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
55 56 57 |
# File 'lib/reactor/tools/migrator.rb', line 55 def filename @filename end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
55 56 57 |
# File 'lib/reactor/tools/migrator.rb', line 55 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
55 56 57 |
# File 'lib/reactor/tools/migrator.rb', line 55 def version @version end |
Instance Method Details
#class_name ⇒ Object
51 52 53 |
# File 'lib/reactor/tools/migrator.rb', line 51 def class_name Kernel.const_get(@name) end |
#down ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/reactor/tools/migrator.rb', line 40 def down result = class_name.send(:down) and @versioner.remove(@version) if result class_name.contained.each do |version| puts "#{class_name} contains migration #{version}" @versioner.remove(version) end end result end |
#load_migration ⇒ Object
14 15 16 |
# File 'lib/reactor/tools/migrator.rb', line 14 def load_migration load @filename end |
#run ⇒ Object
18 19 20 21 22 |
# File 'lib/reactor/tools/migrator.rb', line 18 def run return down if @direction.to_sym == :down up end |
#up ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/reactor/tools/migrator.rb', line 24 def up if @versioner.applied?(@version) puts "Migrating up: #{@name} (#{@filename}) already applied, skipping" true else result = class_name.send(:up) and @versioner.add(@version) if result class_name.contained.each do |version| puts "#{class_name} contains migration #{version}" # @versioner.add(version) # not neccesary! end end result end end |