Class: DataImport::Runner
- Inherits:
-
Object
- Object
- DataImport::Runner
- Defined in:
- lib/data-import/runner.rb
Instance Method Summary collapse
- #before_filter ⇒ Object
- #definition(name) ⇒ Object
-
#initialize(plan) ⇒ Runner
constructor
A new instance of Runner.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(plan) ⇒ Runner
Returns a new instance of Runner.
4 5 6 7 8 9 10 11 |
# File 'lib/data-import/runner.rb', line 4 def initialize(plan) @plan = plan @definitions = Hash[@plan.definitions.map do |definition| [definition.name, definition] end] @executed_definitions = [] end |
Instance Method Details
#before_filter ⇒ Object
38 39 40 |
# File 'lib/data-import/runner.rb', line 38 def before_filter @plan.before_filter end |
#definition(name) ⇒ Object
33 34 35 36 |
# File 'lib/data-import/runner.rb', line 33 def definition(name) raise "no definition found for '#{name}'" unless @definitions[name].present? @definitions[name] end |
#run(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/data-import/runner.rb', line 13 def run( = {}) definitions_to_execute = definitions_for_execution([:only]) while @executed_definitions.count < definitions_to_execute.count did_execute = false definitions_to_execute.each do |name| candidate = definition(name) next if @executed_definitions.include?(name) if (candidate.dependencies - @executed_definitions).blank? candidate.run(self) @executed_definitions << name did_execute = true end end unless did_execute raise "something went wrong! Could not execute all necessary definitions: #{candidate.dependencies - @@executed_definitions}" end end end |