Class: Lono::Layering
Instance Method Summary
collapse
#reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Constructor Details
#initialize(config, options = {}, env = Lono.env, root = Lono.root) ⇒ Layering
Returns a new instance of Layering.
5
6
7
8
9
10
|
# File 'lib/lono/layering.rb', line 5
def initialize(config, options={}, env=Lono.env, root=Lono.root)
super(options)
@config, @options, @env, @root = config, options, env, root
@requested = determine_requested
end
|
Instance Method Details
#always ⇒ Object
21
22
23
24
25
|
# File 'lib/lono/layering.rb', line 21
def always
base = "#{@root}/configs/#{@blueprint}/#{@config}/base"
env = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}"
[base, env]
end
|
#determine_requested ⇒ Object
52
53
54
55
56
|
# File 'lib/lono/layering.rb', line 52
def determine_requested
config_key = @config.singularize.to_sym
@options[config_key] || @options[:config] || @stack
end
|
#direct_layers ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/lono/layering.rb', line 38
def direct_layers
if @requested.starts_with?('/')
[@requested]
else
["#{@root}/#{@requested}"]
end
end
|
#locations ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/lono/layering.rb', line 12
def locations
paths = always + requested
layers = paths.map do |path|
requested_file(path)
end.compact
print_layers(layers)
layers
end
|
#print_layers(layers) ⇒ Object
46
47
48
49
50
|
# File 'lib/lono/layering.rb', line 46
def print_layers(layers)
return unless ENV["LONO_DEBUG_LAYERING"]
puts "layers #{@config}:"
pp layers
end
|
#requested ⇒ Object
27
28
29
|
# File 'lib/lono/layering.rb', line 27
def requested
standard_layers + direct_layers
end
|
#requested_file(path) ⇒ Object
58
59
60
61
62
|
# File 'lib/lono/layering.rb', line 58
def requested_file(path)
paths = [path, "#{path}.txt", "#{path}.sh", "#{path}.rb"].compact
paths.find { |p| File.file?(p) }
end
|
#standard_layers ⇒ Object
31
32
33
34
35
36
|
# File 'lib/lono/layering.rb', line 31
def standard_layers
config_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@requested}"
env_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@requested}"
template_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@template}/#{@requested}"
[config_level, env_level, template_level]
end
|