Class: Tasking::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/tasking/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent_namespace, options = {}, &block) ⇒ Task

Returns a new instance of Task.



6
7
8
9
10
11
12
13
# 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

Instance Attribute Details

#after_filtersObject (readonly)

Returns the value of attribute after_filters.



3
4
5
# File 'lib/tasking/task.rb', line 3

def after_filters
  @after_filters
end

#before_filtersObject (readonly)

Returns the value of attribute before_filters.



3
4
5
# File 'lib/tasking/task.rb', line 3

def before_filters
  @before_filters
end

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/tasking/task.rb', line 3

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tasking/task.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/tasking/task.rb', line 3

def options
  @options
end

#parent_namespaceObject (readonly)

Returns the value of attribute parent_namespace.



3
4
5
# File 'lib/tasking/task.rb', line 3

def parent_namespace
  @parent_namespace
end

Instance Method Details

#add_after_filters(*filters) ⇒ Object



19
20
21
# File 'lib/tasking/task.rb', line 19

def add_after_filters( *filters )
  @after_filters.concat( filters.flatten )
end

#add_before_filters(*filters) ⇒ Object



15
16
17
# File 'lib/tasking/task.rb', line 15

def add_before_filters( *filters )
  @before_filters.concat( filters.flatten )
end

#execute(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# 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