Class: Build::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/build/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, limit: nil) {|_self| ... } ⇒ Controller

Returns a new instance of Controller.

Yields:

  • (_self)

Yield Parameters:



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

#nodesObject (readonly)

Returns the value of attribute nodes.



224
225
226
# File 'lib/build/controller.rb', line 224

def nodes
  @nodes
end

#visualisationObject (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

Yields:

  • (@walker)


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