Class: Orchestra::RunList::Builder
- Inherits:
-
Object
- Object
- Orchestra::RunList::Builder
- Defined in:
- lib/orchestra/run_list.rb
Defined Under Namespace
Classes: Sorter
Instance Attribute Summary collapse
-
#input_names ⇒ Object
readonly
Returns the value of attribute input_names.
Instance Method Summary collapse
- #[]=(name, step) ⇒ Object
- #build ⇒ Object
-
#initialize(result, input_names = []) ⇒ Builder
constructor
A new instance of Builder.
- #merge!(steps) ⇒ Object
- #prune! ⇒ Object
- #remove(step) ⇒ Object
- #require(step) ⇒ Object
- #required?(step) ⇒ Boolean
- #sort! ⇒ Object
- #step_names ⇒ Object
- #steps ⇒ Object
Constructor Details
#initialize(result, input_names = []) ⇒ Builder
Returns a new instance of Builder.
61 62 63 64 65 66 67 |
# File 'lib/orchestra/run_list.rb', line 61 def initialize result, input_names = [] @input_names = input_names @steps_hash = {} @required = Set.new [result] @result = result freeze end |
Instance Attribute Details
#input_names ⇒ Object (readonly)
Returns the value of attribute input_names.
59 60 61 |
# File 'lib/orchestra/run_list.rb', line 59 def input_names @input_names end |
Instance Method Details
#[]=(name, step) ⇒ Object
75 76 77 |
# File 'lib/orchestra/run_list.rb', line 75 def []= name, step @steps_hash[name] = step end |
#build ⇒ Object
87 88 89 90 91 |
# File 'lib/orchestra/run_list.rb', line 87 def build sort! prune! RunList.new @steps_hash, @result end |
#merge!(steps) ⇒ Object
69 70 71 72 73 |
# File 'lib/orchestra/run_list.rb', line 69 def merge! steps steps.each do |name, step| self[name] = step end end |
#prune! ⇒ Object
98 99 100 101 102 103 |
# File 'lib/orchestra/run_list.rb', line 98 def prune! steps.reverse_each.with_object [] do |step, removed| removed.<< remove step and next unless required? step require step end end |
#remove(step) ⇒ Object
105 106 107 108 |
# File 'lib/orchestra/run_list.rb', line 105 def remove step @steps_hash.reject! do |_, n| n == step end step end |
#require(step) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/orchestra/run_list.rb', line 110 def require step supplied_by_input = input_names.method :include? required_deps = step.required_dependencies.reject &supplied_by_input @required.merge required_deps required = @required.method :include? @required.merge step.optional_dependencies.reject &required true end |
#required?(step) ⇒ Boolean
119 120 121 122 |
# File 'lib/orchestra/run_list.rb', line 119 def required? step required = @required.method :include? step.provisions.any? &required end |
#sort! ⇒ Object
93 94 95 96 |
# File 'lib/orchestra/run_list.rb', line 93 def sort! sorter = Sorter.new @steps_hash sorter.sort! end |
#step_names ⇒ Object
79 80 81 |
# File 'lib/orchestra/run_list.rb', line 79 def step_names @steps_hash.keys end |
#steps ⇒ Object
83 84 85 |
# File 'lib/orchestra/run_list.rb', line 83 def steps @steps_hash.values end |