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(logger: nil, limit: nil) {|_self| ... } ⇒ Controller
constructor
A new instance of Controller.
- #run(&block) ⇒ Object
- #update {|@walker| ... } ⇒ Object
Constructor Details
#initialize(logger: nil, limit: nil) {|_self| ... } ⇒ Controller
Returns a new instance of Controller.
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 221 222 |
# File 'lib/build/controller.rb', line 194 def initialize(logger: nil, limit: nil) @module = Module.new @logger = logger || Logger.new($stdout).tap do |logger| logger.level = Logger::INFO logger.formatter = CompactFormatter.new end # Top level nodes: @nodes = [] yield self @nodes.freeze @group = Process::Group.new(limit: limit) # 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.
224 225 226 |
# File 'lib/build/controller.rb', line 224 def nodes @nodes end |
#visualisation ⇒ Object (readonly)
Returns the value of attribute visualisation.
225 226 227 |
# File 'lib/build/controller.rb', line 225 def visualisation @visualisation end |
Instance Method Details
#add_target(target, environment) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/build/controller.rb', line 227 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
249 250 251 252 253 |
# File 'lib/build/controller.rb', line 249 def run(&block) @walker.run do self.update(&block) end end |
#update {|@walker| ... } ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/build/controller.rb', line 236 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 |