Class: Kubes::Compiler::Strategy::Dispatcher
- Inherits:
-
Base
- Object
- Base
- Kubes::Compiler::Strategy::Dispatcher
show all
- Defined in:
- lib/kubes/compiler/strategy/dispatcher.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#pretty_path
Methods included from Logging
#logger
#save_file
#extract_type, #normalize_kind
Methods included from Layering
#add_exts, #post_layers, #pre_layers
Instance Method Details
51
52
53
54
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 51
def block_form?(path)
type = (path)
type.pluralize == type
end
|
#dispatch ⇒ Object
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 3
def dispatch
show_layers if Kubes.config.layering.show
result = render(@path)
results = [result].flatten
data = results.map! do |main|
hash = Kubes.deep_merge!(pre_layer, main)
Kubes.deep_merge!(hash, post_layer)
end
Result.new(@save_file, data)
end
|
#dsl_class(path) ⇒ Object
Must be defined here in case coming from Kubes::Compiler::Strategy::Erb#render
35
36
37
38
39
40
41
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 35
def dsl_class(path)
if block_form?(path)
Kubes::Compiler::Dsl::Core::Blocks
else
syntax_class
end
end
|
#merge_layers(layers) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 64
def merge_layers(layers)
layers.inject({}) do |hash, layer|
data = render(layer)
hash.deep_merge!(data)
end
end
|
#post_layer ⇒ Object
60
61
62
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 60
def post_layer
merge_layers(post_layers)
end
|
#pre_layer ⇒ Object
56
57
58
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 56
def pre_layer
merge_layers(pre_layers)
end
|
#render(path) ⇒ Object
Render via to Erb or one of the DSL syntax classes or Core/Blocks class
24
25
26
27
28
29
30
31
32
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 24
def render(path)
if path.include?('.rb')
klass = dsl_class(path)
klass.new(@options.merge(path: path, data: @data)).run
else
logger.info "Rendering #{pretty_path(path)}" if ENV['KUBES_LAYERING_SHOW_RENDERING']
Erb.new(@options.merge(data: @data)).render_result(path)
end
end
|
#show_layers ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 14
def show_layers
logger.info "Compiling #{pretty_path(@path)}"
logger.info " Resource layers:"
all_layers = pre_layers + [@path] + post_layers
all_layers.each do |layer|
logger.info " #{pretty_path(layer)}"
end
end
|
#syntax_class ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 43
def syntax_class
klass_name = normalize_kind(@save_file)
"Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
rescue NameError
logger.debug "Using default resource for: #{klass_name}"
Kubes::Compiler::Dsl::Syntax::Resource
end
|