Class: Orchestra::Step::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestra/step/output.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hshObject (readonly)

Returns the value of attribute hsh.



4
5
6
# File 'lib/orchestra/step/output.rb', line 4

def hsh
  @hsh
end

#rawObject (readonly)

Returns the value of attribute raw.



4
5
6
# File 'lib/orchestra/step/output.rb', line 4

def raw
  @raw
end

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

Returns:

  • (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_hashObject



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

Returns:

  • (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

#massageObject



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_provisionsObject



43
44
45
# File 'lib/orchestra/step/output.rb', line 43

def missing_provisions
  provisions.reject &included_in_output
end

#provisionsObject



17
18
19
# File 'lib/orchestra/step/output.rb', line 17

def provisions
  step.provisions
end

#pruneObject



51
52
53
# File 'lib/orchestra/step/output.rb', line 51

def prune
  hsh.select! do |key, _| provisions.include? key end
end