Class: Woodhouse::LayoutBuilder::NodeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/woodhouse/layout_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, node) ⇒ NodeBuilder

Returns a new instance of NodeBuilder.



7
8
9
10
# File 'lib/woodhouse/layout_builder.rb', line 7

def initialize(config, node)
  @config = config
  @node = node
end

Instance Method Details

#add(class_name, job_method, opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/woodhouse/layout_builder.rb', line 16

def add(class_name, job_method, opts = {})
  if job_method.kind_of?(Hash)
    # Two-argument invocation
    opts = job_method
    job_method = nil
    methods = @config.registry[class_name].public_instance_methods(false)
  else
    methods = [job_method]
  end
  remove(class_name, job_method, opts.empty? ? nil : opts)
  methods.each do |method|
    @node.add_worker Woodhouse::Layout::Worker.new(class_name, method, opts)
  end
end

#all_workers(options = {}) ⇒ Object



12
13
14
# File 'lib/woodhouse/layout_builder.rb', line 12

def all_workers(options = {})
  @node.default_configuration! @config, options
end

#remove(class_name, job_method = nil, opts = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/woodhouse/layout_builder.rb', line 31

def remove(class_name, job_method = nil, opts = nil)
  @node.workers.select{|worker|
    worker.worker_class_name == class_name &&
      (job_method.nil? || worker.job_method == job_method) &&
      (opts.nil? || worker.criteria.criteria == opts[:only])
  }.each do |worker|
    @node.remove_worker(worker)
  end
end