Class: Migratrix::Migration
- Includes:
- ActiveModel::AttributeMethods, Callbacks, Loggable, MigrationStrategy, ValidOptions
- Defined in:
- lib/migratrix/migration.rb
Overview
Superclass for all migrations. Migratrix COULD check to see that a loaded migration inherits from this class, but hey, duck typing.
Constant Summary
Constants included from Callbacks
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .extend_extraction(extraction_name, options = {}) ⇒ Object
- .extend_load(load_name, options = {}) ⇒ Object
- .extend_transform(transform_name, options = {}) ⇒ Object
- .extractions ⇒ Object
- .loads ⇒ Object
-
.set_extraction(extraction_name, class_name, options = {}) ⇒ Object
extraction crap.
-
.set_load(name, type, options = {}) ⇒ Object
load crap.
-
.set_transform(name, type, options = {}) ⇒ Object
transform crap.
- .transforms ⇒ Object
-
.valid_options ⇒ Object
TODO: Technically, we need to ask our extractions, transformers and loaders for THEIR valid options as well.
Instance Method Summary collapse
- #extractions ⇒ Object
-
#initialize(options = {}) ⇒ Migration
constructor
A new instance of Migration.
- #loads ⇒ Object
- #transforms ⇒ Object
Methods included from Callbacks
#extract, #load, #migrate, #transform
Methods included from MigrationStrategy
#extract, #load, #migrate, #transform
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/migratrix/migration.rb', line 13 def @options end |
Class Method Details
.extend_extraction(extraction_name, options = {}) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/migratrix/migration.rb', line 52 def self.extend_extraction(extraction_name, ={}) migration = ancestors.detect {|k| k.respond_to?(:extractions) && k.extractions[extraction_name]} raise ExtractionNotDefined.new("Could not extend extractar '%s'; no parent Migration defines it" % extraction_name) unless migration extraction = migration.extractions[extraction_name] extractions[extraction_name] = extraction.class.new(extraction_name, extraction..merge()) end |
.extend_load(load_name, options = {}) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/migratrix/migration.rb', line 92 def self.extend_load(load_name, ={}) migration = ancestors.detect {|k| k.respond_to?(:loads) && k.loads[load_name]} raise LoadNotDefined.new("Could not extend extractar '%s'; no parent Migration defines it" % load_name) unless migration load = migration.loads[load_name] loads[load_name] = load.class.new(load_name, load..merge()) end |
.extend_transform(transform_name, options = {}) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/migratrix/migration.rb', line 72 def self.extend_transform(transform_name, ={}) migration = ancestors.detect {|k| k.respond_to?(:transforms) && k.transforms[transform_name]} raise TransformNotDefined.new("Could not extend extractar '%s'; no parent Migration defines it" % transform_name) unless migration transform = migration.transforms[transform_name] transforms[transform_name] = transform.class.new(transform_name, transform..merge()) end |
.extractions ⇒ Object
59 60 61 |
# File 'lib/migratrix/migration.rb', line 59 def self.extractions @extractions ||= {} end |
.loads ⇒ Object
99 100 101 |
# File 'lib/migratrix/migration.rb', line 99 def self.loads @loads ||= {} end |
.set_extraction(extraction_name, class_name, options = {}) ⇒ Object
extraction crap
48 49 50 |
# File 'lib/migratrix/migration.rb', line 48 def self.set_extraction(extraction_name, class_name, ={}) extractions[extraction_name] = Migratrix.extraction(class_name, extraction_name, ) end |
.set_load(name, type, options = {}) ⇒ Object
load crap
88 89 90 |
# File 'lib/migratrix/migration.rb', line 88 def self.set_load(name, type, ={}) loads[name] = Migratrix.load(name, type, ) end |
.set_transform(name, type, options = {}) ⇒ Object
transform crap
68 69 70 |
# File 'lib/migratrix/migration.rb', line 68 def self.set_transform(name, type, ={}) transforms[name] = Migratrix.transform(name, type, ) end |
.transforms ⇒ Object
79 80 81 |
# File 'lib/migratrix/migration.rb', line 79 def self.transforms @transforms ||= {} end |
.valid_options ⇒ Object
TODO: Technically, we need to ask our extractions, transformers and loaders for THEIR valid options as well. limit, offset, order and where are all extraction-only options, and fetchall is an ActiveRecord-specific option
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/migratrix/migration.rb', line 25 def self. opts = super # wacky, I know, but the extended ValidOptions module is in the super chain. (I <3 Ruby) if extractions extractions.each do |name, extraction| opts += extraction. end end if transforms transforms.each do |name, transform| opts += transform. end end # if loads # loads.each do |name, load| # opts += load.valid_options # end # end opts.uniq.sort end |
Instance Method Details
#extractions ⇒ Object
63 64 65 |
# File 'lib/migratrix/migration.rb', line 63 def extractions self.class.extractions end |
#loads ⇒ Object
103 104 105 |
# File 'lib/migratrix/migration.rb', line 103 def loads self.class.loads end |
#transforms ⇒ Object
83 84 85 |
# File 'lib/migratrix/migration.rb', line 83 def transforms self.class.transforms end |