Class: Orchestra::Step::Output
- Inherits:
-
Object
- Object
- Orchestra::Step::Output
- Defined in:
- lib/orchestra/step/output.rb
Instance Attribute Summary collapse
-
#hsh ⇒ Object
readonly
Returns the value of attribute hsh.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
Class Method Summary collapse
Instance Method Summary collapse
- #all_provisions_supplied?(hsh = @hsh) ⇒ Boolean
- #coerce_to_hash ⇒ Object
- #collection? ⇒ Boolean
- #ensure_all_provisions_supplied! ⇒ Object
- #included_in_output(hsh = @hsh) ⇒ Object
-
#initialize(step, raw) ⇒ Output
constructor
A new instance of Output.
- #massage ⇒ Object
- #missing_provisions ⇒ Object
- #provisions ⇒ Object
- #prune ⇒ Object
Constructor Details
#initialize(step, raw) ⇒ Output
Returns a new instance of Output.
12 13 14 15 |
# File 'lib/orchestra/step/output.rb', line 12 def initialize step, raw @step = step @raw = raw end |
Instance Attribute Details
#hsh ⇒ Object (readonly)
Returns the value of attribute hsh.
4 5 6 |
# File 'lib/orchestra/step/output.rb', line 4 def hsh @hsh end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
4 5 6 |
# File 'lib/orchestra/step/output.rb', line 4 def raw @raw end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
4 5 6 |
# File 'lib/orchestra/step/output.rb', line 4 def step @step end |
Class Method Details
.process(step, raw) ⇒ Object
6 7 8 9 10 |
# File 'lib/orchestra/step/output.rb', line 6 def self.process step, raw instance = new step, raw instance.massage instance.hsh end |
Instance Method Details
#all_provisions_supplied?(hsh = @hsh) ⇒ Boolean
39 40 41 |
# File 'lib/orchestra/step/output.rb', line 39 def all_provisions_supplied? hsh = @hsh provisions.all? &included_in_output(hsh) end |
#coerce_to_hash ⇒ Object
32 33 34 35 36 37 |
# File 'lib/orchestra/step/output.rb', line 32 def coerce_to_hash return Hash(raw) unless provisions.size == 1 return raw if all_provisions_supplied? raw if raw.kind_of? Hash raise MissingProvisionError.new provisions if raw.nil? { provisions.first => raw } end |
#collection? ⇒ Boolean
21 22 23 |
# File 'lib/orchestra/step/output.rb', line 21 def collection? step.collection? end |
#ensure_all_provisions_supplied! ⇒ Object
55 56 57 58 |
# File 'lib/orchestra/step/output.rb', line 55 def ensure_all_provisions_supplied! return if all_provisions_supplied? raise MissingProvisionError.new missing_provisions end |
#included_in_output(hsh = @hsh) ⇒ Object
47 48 49 |
# File 'lib/orchestra/step/output.rb', line 47 def included_in_output hsh = @hsh hsh.keys.method :include? end |
#massage ⇒ Object
25 26 27 28 29 30 |
# File 'lib/orchestra/step/output.rb', line 25 def massage @raw.compact! if collection? @hsh = coerce_to_hash prune ensure_all_provisions_supplied! end |
#missing_provisions ⇒ Object
43 44 45 |
# File 'lib/orchestra/step/output.rb', line 43 def missing_provisions provisions.reject &included_in_output end |
#provisions ⇒ Object
17 18 19 |
# File 'lib/orchestra/step/output.rb', line 17 def provisions step.provisions end |
#prune ⇒ Object
51 52 53 |
# File 'lib/orchestra/step/output.rb', line 51 def prune hsh.select! do |key, _| provisions.include? key end end |