Class: Lono::Configset::Loader
- Inherits:
-
Object
- Object
- Lono::Configset::Loader
show all
- Extended by:
- Memoist
- Includes:
- EvaluateFile, Dsl
- Defined in:
- lib/lono/configset/loader.rb,
lib/lono/configset/loader/dsl.rb
Defined Under Namespace
Modules: Dsl
Instance Method Summary
collapse
#evaluate_file
Methods included from Dsl
#indent
Constructor Details
#initialize(registry = {}, options = {}) ⇒ Loader
Returns a new instance of Loader.
9
10
11
12
13
|
# File 'lib/lono/configset/loader.rb', line 9
def initialize(registry={}, options={})
@registry, @options = registry, options
@name, @resource = registry.name, registry.resource
@blueprint = Lono::Conventions.new(options).blueprint
end
|
Instance Method Details
#configset_root ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/lono/configset/loader.rb', line 45
def configset_root
config = finder_class.find(@name)
unless config
puts "finder_class #{finder_class}"
raise "Unable to find configset #{@name.inspect}"
end
config.root
end
|
#copy_instance_variables ⇒ Object
59
60
61
62
63
|
# File 'lib/lono/configset/loader.rb', line 59
def copy_instance_variables
load_blueprint_predefined_variables
load_project_predefined_variables
load_inline_project_variables
end
|
#find_path ⇒ Object
40
41
42
43
|
# File 'lib/lono/configset/loader.rb', line 40
def find_path
paths = %w[configset.yml configset.json].map { |p| "#{configset_root}/lib/#{p}" }
paths.find { |p| File.exist?(p) }
end
|
#finder_class ⇒ Object
Allow overriding in subclasses
55
56
57
|
# File 'lib/lono/configset/loader.rb', line 55
def finder_class
Lono::Finder::Configset
end
|
#load ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/lono/configset/loader.rb', line 19
def load
path = find_path
copy_instance_variables
content = RenderMePretty.result(path, context: self)
if File.extname(path) == ".yml"
load_yaml(content)
else
JSON.load(content)
end
end
|
#load_blueprint_predefined_variables ⇒ Object
65
66
67
68
|
# File 'lib/lono/configset/loader.rb', line 65
def load_blueprint_predefined_variables
path = "#{configset_root}/lib/variables.rb"
evaluate_file(path)
end
|
#load_inline_project_variables ⇒ Object
Copy options from the original configset call as instance variables so its available. So:
configset("ssm", resource: "Instance", some_var: "test")
Stores in the Configset::Registry
register = {name: "ssm", resource: "Instance", some_var: "test"}
That has is passed into Loader.new(register, options)
So these @registry varibles are copied over to instance variables.
92
93
94
95
96
|
# File 'lib/lono/configset/loader.rb', line 92
def load_inline_project_variables
@registry.vars.each do |k,v|
instance_variable_set("@#{k}", v)
end
end
|
#load_project_predefined_variables ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/lono/configset/loader.rb', line 70
def load_project_predefined_variables
paths = [
"#{Lono.root}/configs/#{@blueprint}/configsets/variables.rb", "#{Lono.root}/configs/#{@blueprint}/configsets/#{@name}/variables.rb", ]
paths.each do |path|
evaluate_file(path)
end
end
|
#load_yaml(content) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/lono/configset/loader.rb', line 31
def load_yaml(content)
path = "/tmp/lono/configset.yml"
FileUtils.mkdir_p(File.dirname(path))
IO.write(path, content)
Lono::Yamler::Validator.new(path).validate!
Lono::Yamler::Loader.new(content).load
end
|
#metdata_configset ⇒ Object
15
16
17
|
# File 'lib/lono/configset/loader.rb', line 15
def metdata_configset
load
end
|