Class: Seedbank::Runner

Inherits:
Module
  • Object
show all
Defined in:
lib/seedbank/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Runner

Returns a new instance of Runner.



4
5
6
7
# File 'lib/seedbank/runner.rb', line 4

def initialize(task)
  @task = task
  super()
end

Instance Method Details

#after(*dependencies, &block) ⇒ Object

Run this seed after the specified dependencies have run If a block is specified the contents of the block are executed after all the dependencies have been executed.

If no block is specified just the dependencies are run. This makes it possible to create shared dependencies. For example

Would look for a db/seeds/shared/users.seeds.rb seed and execute it.

Examples:

db/seeds/production/users.seeds.rb

after 'shared:users'

Parameters:

  • dependencies (Array)

    seeds to run before the block is executed



22
23
24
25
26
27
28
# File 'lib/seedbank/runner.rb', line 22

def after(*dependencies, &block)
  dependencies.flatten!
  dependencies.map! { |dep| "db:seed:#{dep}"}
  dependent_task_name =  @task.name + ':body'
  dependent_task = Rake::Task.define_task(dependent_task_name => dependencies, &block)
  dependent_task.invoke
end