Class: Lono::ConfigLocation
Constant Summary
collapse
- @@using_message_displayed =
{}
Instance Method Summary
collapse
#reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Constructor Details
#initialize(config, options = {}, env = Lono.env, root = Lono.root) ⇒ ConfigLocation
Returns a new instance of ConfigLocation.
5
6
7
8
9
10
|
# File 'lib/lono/config_location.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
#determine_requested ⇒ Object
Some switching logic between variable and param below
68
69
70
71
72
|
# File 'lib/lono/config_location.rb', line 68
def determine_requested
config_key = @config.singularize.to_sym @options[config_key] || @options[:config] || @stack
end
|
#direct_levels ⇒ Object
34
35
36
37
38
39
|
# File 'lib/lono/config_location.rb', line 34
def direct_levels
[
@requested, "#{@root}/#{@requested}", ]
end
|
#lookup ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/lono/config_location.rb', line 12
def lookup
levels = []
levels += direct_levels
template_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@template}/#{@requested}"
env_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@requested}"
config_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@requested}"
generic_env = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}"
levels += [template_level, env_level, config_level, generic_env]
print_levels(levels)
found = levels.find do |level|
requested_file(level)
end
if found
file = requested_file(found)
using_message(file, @env)
file
end
end
|
#lookup_base ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/lono/config_location.rb', line 41
def lookup_base
base = "#{@root}/configs/#{@blueprint}/#{@config}/base"
file = requested_file(base)
if file
using_message(file, "base")
file
end
end
|
#print_levels(levels) ⇒ Object
50
51
52
53
54
|
# File 'lib/lono/config_location.rb', line 50
def print_levels(levels)
return unless ENV["LONO_DEBUG_CONFIG"]
puts "levels #{@config}:"
pp levels
end
|
#requested_file(path) ⇒ Object
74
75
76
77
78
|
# File 'lib/lono/config_location.rb', line 74
def requested_file(path)
paths = [path, "#{path}.txt", "#{path}.sh", "#{path}.rb"].compact
paths.find { |p| File.file?(p) }
end
|
#using_message(file, type) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/lono/config_location.rb', line 57
def using_message(file, type)
return if @@using_message_displayed[file]
pretty_file = file.sub("#{Lono.root}/", "")
puts "Using #{@config} for #{type}: #{pretty_file}"
@@using_message_displayed[file] = true
end
|