Class: Build::Controller
- Inherits:
-
Object
- Object
- Build::Controller
- Defined in:
- lib/build/controller.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#visualisation ⇒ Object
readonly
Returns the value of attribute visualisation.
Instance Method Summary collapse
- #add_target(target, environment) ⇒ Object
-
#initialize {|_self| ... } ⇒ Controller
constructor
A new instance of Controller.
- #run(&block) ⇒ Object
- #update {|@walker| ... } ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Controller
Returns a new instance of Controller.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/build/controller.rb', line 187 def initialize @module = Module.new @logger = Logger.new($stdout) @logger.level = Logger::INFO @logger.formatter = CompactFormatter.new # Top level nodes: @nodes = [] yield self @nodes.freeze @group = Process::Group.new # The task class is captured as we traverse all the top level targets: @task_class = nil @walker = Graph::Walker.new do |walker, node| # Instantiate the task class here: task = @task_class.new(walker, node, @group, logger: @logger) task.visit do task.update end end end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
216 217 218 |
# File 'lib/build/controller.rb', line 216 def nodes @nodes end |
#visualisation ⇒ Object (readonly)
Returns the value of attribute visualisation.
217 218 219 |
# File 'lib/build/controller.rb', line 217 def visualisation @visualisation end |
Instance Method Details
#add_target(target, environment) ⇒ Object
219 220 221 222 223 224 225 226 |
# File 'lib/build/controller.rb', line 219 def add_target(target, environment) task_class = Rulebook.for(environment).with(Task, environment: environment, target: target) # Not sure if this is a good idea - makes debugging slightly easier. Object.const_set("TaskClassFor#{Name.from_target(target.name).identifier}_#{self.object_id}", task_class) @nodes << TargetNode.new(task_class, &target.build) end |
#run(&block) ⇒ Object
241 242 243 244 245 |
# File 'lib/build/controller.rb', line 241 def run(&block) @walker.run do self.update(&block) end end |
#update {|@walker| ... } ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/build/controller.rb', line 228 def update @nodes.each do |node| # Update the task class here: @task_class = node.task_class @walker.call(node) end @group.wait yield @walker if block_given? end |