Class: Tap::Declarations::DeclarationTask

Inherits:
Task show all
Defined in:
lib/tap/declarations/declaration_task.rb

Overview

Dependency tasks are a singleton version of tasks. Dependency tasks only have one instance (DeclarationTask.instance) and the instance is registered as a dependency, so it will only execute once.

Constant Summary

Constants inherited from Task

Task::DEFAULT_HELP_TEMPLATE

Class Attribute Summary collapse

Attributes inherited from Task

#name

Attributes included from Support::Executable

#app, #batch, #dependencies, #method_name, #on_complete_block

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Task

execute, help, inherited, #initialize, #initialize_batch_obj, #inspect, instance, intern, load, #log, parse, parse!, #to_s, use

Methods included from Support::Executable

#_execute, #batch_index, #batch_with, #batched?, #check_terminate, #depends_on, #enq, #execute, #fork, initialize, #initialize_batch_obj, #merge, #on_complete, #reset_dependencies, #resolve_dependencies, #sequence, #switch, #sync_merge, #unbatched_depends_on, #unbatched_enq, #unbatched_on_complete

Constructor Details

This class inherits a constructor from Tap::Task

Class Attribute Details

.arg_namesObject



18
19
20
# File 'lib/tap/declarations/declaration_task.rb', line 18

def arg_names
  @arg_names ||= []
end

.blocksObject



12
13
14
# File 'lib/tap/declarations/declaration_task.rb', line 12

def blocks
  @blocks ||= []
end

Class Method Details

.argsObject



29
30
31
32
33
# File 'lib/tap/declarations/declaration_task.rb', line 29

def args
  args = Lazydoc::Arguments.new
  arg_names.each {|name| args.arguments << name.to_s }
  args
end

.new(*args) ⇒ Object

Initializes instance and registers it as a dependency.



23
24
25
26
27
# File 'lib/tap/declarations/declaration_task.rb', line 23

def new(*args)
  @instance ||= super
  @instance.app.dependencies.register(@instance)
  @instance
end

Instance Method Details

#process(*inputs) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tap/declarations/declaration_task.rb', line 36

def process(*inputs)
  # collect inputs to make a rakish-args object
  args = {}
  self.class.arg_names.each do |arg_name|
    break if inputs.empty?
    args[arg_name] = inputs.shift
  end
  args = OpenStruct.new(args)
  
  # execute each block assciated with this task
  self.class.blocks.each do |task_block|
    case task_block.arity
    when 0 then task_block.call()
    when 1 then task_block.call(self)
    else task_block.call(self, args)
    end
  end
  
  nil
end