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 {|_self| ... } ⇒ Controller

Returns a new instance of Controller.

Yields:

  • (_self)

Yield Parameters:



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

#nodesObject (readonly)

Returns the value of attribute nodes.



216
217
218
# File 'lib/build/controller.rb', line 216

def nodes
  @nodes
end

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

Yields:

  • (@walker)


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