Class: Rscons::Task
- Inherits:
-
Object
- Object
- Rscons::Task
- Defined in:
- lib/rscons/task.rb
Overview
A task is a named collection of actions and/or dependencies.
Defined Under Namespace
Classes: Param
Instance Attribute Summary collapse
-
#actions ⇒ Array<Proc>
readonly
Task action blocks.
-
#autoconf ⇒ Boolean
readonly
Whether to automatically configure before running this task.
-
#description ⇒ String?
readonly
Task description, if given.
-
#name ⇒ String
readonly
Task name.
-
#param_values ⇒ Hash<String => String>
readonly
Task parameter values.
-
#params ⇒ Hash<String => Param>
readonly
Task params.
Class Method Summary collapse
-
.[](name = nil) ⇒ Hash, ...
Access a task by name.
-
.register(task) ⇒ void
private
Register a newly created task.
-
.tasks ⇒ Hash
private
Get all registered tasks.
Instance Method Summary collapse
-
#[](param_name) ⇒ String
Get a parameter’s value.
-
#check_execute ⇒ void
Check if the task has been executed, and if not execute it.
-
#execute ⇒ void
Execute a task’s actions.
-
#executed? ⇒ Boolean
Check if the task has been executed.
-
#initialize(name, options, &block) ⇒ Task
constructor
Construct a task.
-
#modify(options, &block) ⇒ void
private
Modify a task.
-
#set_param_value(param_name, param_value) ⇒ void
Set parameter value.
Constructor Details
#initialize(name, options, &block) ⇒ Task
Construct a task.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rscons/task.rb', line 123 def initialize(name, , &block) @autoconf = true @dependencies = [] @description = nil @name = name @params = {} @param_values = {} @actions = [] Task.register(self) modify(, &block) end |
Instance Attribute Details
#actions ⇒ Array<Proc> (readonly)
Returns Task action blocks.
92 93 94 |
# File 'lib/rscons/task.rb', line 92 def actions @actions end |
#autoconf ⇒ Boolean (readonly)
Returns Whether to automatically configure before running this task.
96 97 98 |
# File 'lib/rscons/task.rb', line 96 def autoconf @autoconf end |
#description ⇒ String? (readonly)
Returns Task description, if given.
100 101 102 |
# File 'lib/rscons/task.rb', line 100 def description @description end |
#name ⇒ String (readonly)
Returns Task name.
104 105 106 |
# File 'lib/rscons/task.rb', line 104 def name @name end |
#param_values ⇒ Hash<String => String> (readonly)
Returns Task parameter values.
112 113 114 |
# File 'lib/rscons/task.rb', line 112 def param_values @param_values end |
#params ⇒ Hash<String => Param> (readonly)
Returns Task params.
108 109 110 |
# File 'lib/rscons/task.rb', line 108 def params @params end |
Class Method Details
.[](name = nil) ⇒ Hash, ...
Access a task by name.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rscons/task.rb', line 16 def [](name = nil) if name if task = tasks[name] task else raise RsconsError.new("Task '#{name}' not found") end else tasks end end |
.register(task) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Register a newly created task.
36 37 38 |
# File 'lib/rscons/task.rb', line 36 def register(task) tasks[task.name] = task end |
.tasks ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get all registered tasks.
46 47 48 |
# File 'lib/rscons/task.rb', line 46 def tasks @tasks ||= {} end |
Instance Method Details
#[](param_name) ⇒ String
Get a parameter’s value.
142 143 144 145 146 147 148 |
# File 'lib/rscons/task.rb', line 142 def [](param_name) param = @params[param_name] unless param raise RsconsError.new("Could not find parameter '#{param_name}'") end @param_values[param_name] end |
#check_execute ⇒ void
This method returns an undefined value.
Check if the task has been executed, and if not execute it.
175 176 177 178 179 |
# File 'lib/rscons/task.rb', line 175 def check_execute unless executed? execute end end |
#execute ⇒ void
This method returns an undefined value.
Execute a task’s actions.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rscons/task.rb', line 153 def execute @executed = true if @autoconf Rscons.application.check_configure Rscons.application.check_process_environments end @dependencies.each do |dependency| Task[dependency].check_execute end if @name == "configure" Rscons.application.silent_configure = false Rscons.application.configure else @actions.each do |action| action[self, param_values] end end end |
#executed? ⇒ Boolean
Check if the task has been executed.
185 186 187 |
# File 'lib/rscons/task.rb', line 185 def executed? @executed end |
#modify(options, &block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Modify a task.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/rscons/task.rb', line 194 def modify(, &block) if .include?(:autoconf) @autoconf = [:autoconf] end if .include?(:desc) @description = [:desc] end if .include?(:depends) @dependencies += Array([:depends]) end if .include?(:params) Array([:params]).each do |param| @params[param.name] = param set_param_value(param.name, param.value) end end if block if env = Environment.running_environment @actions << proc do block[] env.process end else @actions << block end end end |
#set_param_value(param_name, param_value) ⇒ void
This method returns an undefined value.
Set parameter value.
230 231 232 233 234 235 |
# File 'lib/rscons/task.rb', line 230 def set_param_value(param_name, param_value) if param = @params[param_name] param.value = param_value end @param_values[param_name] = param_value end |