Class: Lono::ConfigLocation
- Inherits:
-
Object
- Object
- Lono::ConfigLocation
show all
- Extended by:
- Memoist
- Includes:
- Conventions
- Defined in:
- lib/lono/config_location.rb
Constant Summary
collapse
- @@using_message_displayed =
{}
Instance Method Summary
collapse
#template_param_convention
Constructor Details
#initialize(config, options = {}, env = Lono.env, root = Lono.root) ⇒ ConfigLocation
Returns a new instance of ConfigLocation.
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/lono/config_location.rb', line 6
def initialize(config, options={}, env=Lono.env, root=Lono.root)
@config, @options, @root, @env = config, options, root, env
@stack = options[:stack]
@blueprint = options[:blueprint] || @stack
@template, @param = template_param_convention(options)
@requested = determine_requested
end
|
Instance Method Details
#determine_requested ⇒ Object
Some switching logic between variable and param below
73
74
75
76
77
|
# File 'lib/lono/config_location.rb', line 73
def determine_requested
config_key = @config.singularize.to_sym @options[config_key] || @options[:config] || @options[:stack]
end
|
#direct_levels ⇒ Object
39
40
41
42
43
44
|
# File 'lib/lono/config_location.rb', line 39
def direct_levels
[
@requested, "#{@root}/#{@requested}", ]
end
|
#lookup ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/lono/config_location.rb', line 17
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
46
47
48
49
50
51
52
53
|
# File 'lib/lono/config_location.rb', line 46
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
55
56
57
58
59
|
# File 'lib/lono/config_location.rb', line 55
def print_levels(levels)
return unless ENV["LONO_DEBUG_CONFIG"]
puts "levels #{@config}:"
pp levels
end
|
#requested_file(path) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/lono/config_location.rb', line 79
def requested_file(path)
paths = @config == "params" ?
[path, "#{path}.txt", "#{path}.sh"] :
[path, "#{path}.rb"]
paths.find { |p| File.file?(p) }
end
|
#using_message(file, type) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/lono/config_location.rb', line 62
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
|