Class: Kubes::Compiler::Strategy::Result
- Inherits:
-
Object
- Object
- Kubes::Compiler::Strategy::Result
show all
- Includes:
- Util::YamlDump
- Defined in:
- lib/kubes/compiler/strategy/result.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#standardize_yaml, #yaml_dump
Constructor Details
#initialize(filename, data) ⇒ Result
Returns a new instance of Result.
6
7
8
|
# File 'lib/kubes/compiler/strategy/result.rb', line 6
def initialize(filename, data)
@filename, @data = filename, data
end
|
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
5
6
7
|
# File 'lib/kubes/compiler/strategy/result.rb', line 5
def filename
@filename
end
|
Instance Method Details
#content ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/kubes/compiler/strategy/result.rb', line 23
def content
data = filter_skip(@data)
data.each { |item| item.delete('kubes') }
return if data.empty?
result = data.size == 1 ? data.first : data
yaml_dump(result)
end
|
#decorate!(phase) ⇒ Object
decorate(:pre) or decorate(:post)
15
16
17
18
19
20
21
|
# File 'lib/kubes/compiler/strategy/result.rb', line 15
def decorate!(phase)
klass = "Kubes::Compiler::Decorator::#{phase.to_s.camelize}".constantize
results = [@data].flatten
results.map! do |r|
klass.new(r).result
end
end
|
#filter_skip(data) ⇒ Object
35
36
37
38
39
|
# File 'lib/kubes/compiler/strategy/result.rb', line 35
def filter_skip(data)
data.reject do |item|
item.dig('kubes', 'skip')
end
end
|
#io? ⇒ Boolean
10
11
12
|
# File 'lib/kubes/compiler/strategy/result.rb', line 10
def io?
@data.respond_to?(:read)
end
|
#skip? ⇒ Boolean
31
32
33
|
# File 'lib/kubes/compiler/strategy/result.rb', line 31
def skip?
content.nil?
end
|