class Tasking::Task

Attributes

after_filters[R]
before_filters[R]
block[R]
name[R]
options[R]
parent_namespace[R]

Public Class Methods

new( name, parent_namespace, options = {}, &block ) click to toggle source
# File lib/tasking/task.rb, line 6
def initialize( name, parent_namespace, options = {}, &block )
  @name             = name
  @parent_namespace = parent_namespace
  @options          = Options.build( options )
  @block            = block
  @before_filters   = []
  @after_filters    = []
end

Public Instance Methods

add_after_filters( *filters ) click to toggle source
# File lib/tasking/task.rb, line 19
def add_after_filters( *filters )
  @after_filters.concat( filters.flatten )
end
add_before_filters( *filters ) click to toggle source
# File lib/tasking/task.rb, line 15
def add_before_filters( *filters )
  @before_filters.concat( filters.flatten )
end
execute( options = {} ) click to toggle source
# File lib/tasking/task.rb, line 23
def execute( options = {} )
  total_options = Options.build(parent_namespace.options.dup)
  total_options.merge!( @options )
  total_options.merge!( options )

  execute_task_chain( before_filters, total_options, "Unknown before task '%s' for task '#{@name}'" )
  block&.call( total_options )
  execute_task_chain( after_filters, total_options, "Unknown after task '%s' for task '#{@name}'" )
end

Private Instance Methods

execute_task_chain( tasks, options, fail_message ) click to toggle source
# File lib/tasking/task.rb, line 35
def execute_task_chain( tasks, options, fail_message )
  tasks.each do |t|
    task = task_lookup( t )
    abort( fail_message % t ) unless task
    task.execute( options )
  end
end
task_lookup( name ) click to toggle source
# File lib/tasking/task.rb, line 43
def task_lookup( name )
  name.slice!( 0, 2 ) if name.start_with?( '::' ) 
  Tasking::Namespace.find_task( name )
end