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
52
53
54
55
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 52
def block_form?(path)
type = (path)
type.pluralize == type
end
|
#dispatch ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
|
# 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
logger.info "Compiled .kubes/output/#{@save_file}" if Kubes.config.layering.show
Result.new(@save_file, data)
end
|
#dsl_class(path) ⇒ Object
Must be defined here in case coming from Kubes::Compiler::Strategy::Erb#render
36
37
38
39
40
41
42
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 36
def dsl_class(path)
if block_form?(path)
Kubes::Compiler::Dsl::Core::Blocks
else
syntax_class
end
end
|
#merge_layers(layers) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 65
def merge_layers(layers)
layers.inject({}) do |hash, layer|
data = render(layer)
hash.deep_merge!(data)
end
end
|
#post_layer ⇒ Object
61
62
63
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 61
def post_layer
merge_layers(post_layers)
end
|
#pre_layer ⇒ Object
57
58
59
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 57
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
25
26
27
28
29
30
31
32
33
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 25
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
15
16
17
18
19
20
21
22
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 15
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
44
45
46
47
48
49
50
|
# File 'lib/kubes/compiler/strategy/dispatcher.rb', line 44
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
|