Class: Abid::Task
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Abid::Task
- Extended by:
- Forwardable
- Defined in:
- lib/abid/task.rb
Instance Attribute Summary collapse
-
#extends ⇒ Object
Returns the value of attribute extends.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#play ⇒ Object
readonly
Returns the value of attribute play.
-
#play_class_definition ⇒ Object
Returns the value of attribute play_class_definition.
Class Method Summary collapse
-
.define_play(*args, &block) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #bind(**params) ⇒ Object
- #bound? ⇒ Boolean
-
#execute(_args = nil) ⇒ Object
Execute the play associated with this task.
-
#initialize(task_name, app) ⇒ Task
constructor
A new instance of Task.
-
#name_with_args ⇒ Object
Name of task with argument list description.
-
#name_with_params ⇒ Object
Name of task with params.
- #params_description ⇒ Object
- #play_class ⇒ Object
- #prerequisite_tasks ⇒ Object
Constructor Details
#initialize(task_name, app) ⇒ Task
Returns a new instance of Task.
10 11 12 13 |
# File 'lib/abid/task.rb', line 10 def initialize(task_name, app) super(task_name, app) @siblings = {} end |
Instance Attribute Details
#extends ⇒ Object
Returns the value of attribute extends.
5 6 7 |
# File 'lib/abid/task.rb', line 5 def extends @extends end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/abid/task.rb', line 6 def params @params end |
#play ⇒ Object (readonly)
Returns the value of attribute play.
6 7 8 |
# File 'lib/abid/task.rb', line 6 def play @play end |
#play_class_definition ⇒ Object
Returns the value of attribute play_class_definition.
5 6 7 |
# File 'lib/abid/task.rb', line 5 def play_class_definition @play_class_definition end |
Class Method Details
.define_play(*args, &block) ⇒ Object
:nodoc:
118 119 120 |
# File 'lib/abid/task.rb', line 118 def define_play(*args, &block) # :nodoc: Rake.application.define_play(self, *args, &block) end |
Instance Method Details
#bind(**params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/abid/task.rb', line 28 def bind(**params) fail 'already bound' if bound? parsed_params = ParamsParser.parse(params, play_class.params_spec) return @siblings[parsed_params] if @siblings.include?(parsed_params) sorted_params = parsed_params.sort.to_h sorted_params.freeze @siblings[sorted_params] = dup.tap do |t| t.instance_eval do @prerequisites = [] @params = sorted_params @play = play_class.new(t) end play_class.hooks[:setup].each { |blk| t.play.instance_eval(&blk) } end end |
#bound? ⇒ Boolean
24 25 26 |
# File 'lib/abid/task.rb', line 24 def bound? !@play.nil? end |
#execute(_args = nil) ⇒ Object
Execute the play associated with this task.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/abid/task.rb', line 89 def execute(_args = nil) fail 'no play is bound yet' unless bound? if application..dryrun application.trace "** Execute (dry run) #{name_with_params}" return end if application..trace application.trace "** Execute #{name_with_params}" end play_class.hooks[:before].each { |blk| play.instance_eval(&blk) } call_around_hooks(play_class.hooks[:around]) { play.run } play_class.hooks[:after].each { |blk| play.instance_eval(&blk) } end |
#name_with_args ⇒ Object
Name of task with argument list description.
56 57 58 59 60 61 62 |
# File 'lib/abid/task.rb', line 56 def name_with_args # :nodoc: if params_description "#{super} #{params_description}" else super end end |
#name_with_params ⇒ Object
Name of task with params
65 66 67 68 69 70 71 |
# File 'lib/abid/task.rb', line 65 def name_with_params # :nodoc: if params_description "#{name} #{params_description}" else super end end |
#params_description ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/abid/task.rb', line 73 def params_description sig_params = play_class.params_spec.select do |_, spec| spec[:significant] end return if sig_params.empty? if bound? # unbound p = sig_params.map { |name, _| "#{name}=#{params[name]}" } else p = sig_params.map { |name, spec| "#{name}:#{spec[:type]}" } end p.join(' ') end |
#play_class ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/abid/task.rb', line 15 def play_class return @play_class if @play_class klass = application.lookup_play_class(extends, scope) @play_class = Class.new(klass, &play_class_definition).tap do |c| c.task = self end end |
#prerequisite_tasks ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/abid/task.rb', line 47 def prerequisite_tasks fail 'no play is bound yet' unless bound? prerequisites.map do |pre, params| application[pre, @scope, **self.params.merge(params)] end end |