Class: Aef::Migrator
- Inherits:
-
Object
- Object
- Aef::Migrator
- Defined in:
- lib/aef/migrator/migrator.rb
Overview
Class for building general purpose versioning systems in the style of ActiveRecord’s migrations. An adapter object is needed for any instance of this class to have any use. See Adapter and AbstractAdapter for the required interface.
Defined Under Namespace
Modules: Adapter Classes: AbstractAdapter, AdapterError, AdapterMethodMissingError, AdapterMissingError, AlreadyOnBottomError, AlreadyOnTopError, CurrentVersionInvalidError, DownMigrationInvalidError, Error, MigrationError, MigrationUnneccessaryError, TargetVersionInvalidError, UpMigrationInvalidError
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#down(target_version = nil) ⇒ Object
Process a down migration.
-
#downable?(target_version = nil) ⇒ Boolean
Checks if a down migration is possible.
-
#initialize(adapter) ⇒ Migrator
constructor
A new instance of Migrator.
-
#migratable?(target_version, direction = nil) ⇒ Boolean
Checks if a migration is possible.
-
#migrate(target_version, direction = nil) ⇒ Object
Process a migration.
-
#up(target_version = nil) ⇒ Object
Process an up migration.
-
#upable?(target_version = nil) ⇒ Boolean
Checks if an up migration is possible.
-
#version ⇒ Object
Current version.
-
#versions ⇒ Object
All possible versions in correct order.
Constructor Details
#initialize(adapter) ⇒ Migrator
Returns a new instance of Migrator.
48 49 50 |
# File 'lib/aef/migrator/migrator.rb', line 48 def initialize(adapter) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
46 47 48 |
# File 'lib/aef/migrator/migrator.rb', line 46 def adapter @adapter end |
Instance Method Details
#down(target_version = nil) ⇒ Object
Process a down migration
Raises MigratorError in case of invalid actions
92 93 94 |
# File 'lib/aef/migrator/migrator.rb', line 92 def down(target_version = nil) migrate(target_version, :down) end |
#downable?(target_version = nil) ⇒ Boolean
Checks if a down migration is possible
65 66 67 |
# File 'lib/aef/migrator/migrator.rb', line 65 def downable?(target_version = nil) migratable?(target_version, :down) end |
#migratable?(target_version, direction = nil) ⇒ Boolean
Checks if a migration is possible
53 54 55 56 57 |
# File 'lib/aef/migrator/migrator.rb', line 53 def migratable?(target_version, direction = nil) !!migration_steps(target_version, direction) rescue MigrationError false end |
#migrate(target_version, direction = nil) ⇒ Object
Process a migration
Raises MigratorError in case of invalid actions
72 73 74 75 76 77 78 79 80 |
# File 'lib/aef/migrator/migrator.rb', line 72 def migrate(target_version, direction = nil) params = migration_steps(target_version, direction) params[:steps].each do |version| @adapter.send(params[:action], version) end self end |
#up(target_version = nil) ⇒ Object
Process an up migration
Raises MigratorError in case of invalid actions
85 86 87 |
# File 'lib/aef/migrator/migrator.rb', line 85 def up(target_version = nil) migrate(target_version, :up) end |
#upable?(target_version = nil) ⇒ Boolean
Checks if an up migration is possible
60 61 62 |
# File 'lib/aef/migrator/migrator.rb', line 60 def upable?(target_version = nil) migratable?(target_version, :up) end |
#version ⇒ Object
Current version
97 98 99 |
# File 'lib/aef/migrator/migrator.rb', line 97 def version @adapter.version end |
#versions ⇒ Object
All possible versions in correct order
102 103 104 |
# File 'lib/aef/migrator/migrator.rb', line 102 def versions @adapter.versions end |