Class: Lono::Configset::Register::Base
Class Method Summary
collapse
Instance Method Summary
collapse
#evaluate_file
Methods included from Dsl
#configset
#initialize, #reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Class Method Details
.append(registry) ⇒ Object
113
114
115
|
# File 'lib/lono/configset/register/base.rb', line 113
def append(registry)
self.configsets << registry unless has?(registry)
end
|
.clear! ⇒ Object
104
105
106
107
|
# File 'lib/lono/configset/register/base.rb', line 104
def clear!
self.configsets = []
self.validations = []
end
|
.has?(registry) ⇒ Boolean
117
118
119
|
# File 'lib/lono/configset/register/base.rb', line 117
def has?(registry)
configsets.detect { |r| r.name == registry.name && r.args == registry.args }
end
|
.prepend(registry) ⇒ Object
109
110
111
|
# File 'lib/lono/configset/register/base.rb', line 109
def prepend(registry)
self.configsets.unshift(registry) unless has?(registry)
end
|
Instance Method Details
#finder_class ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/lono/configset/register/base.rb', line 31
def finder_class
case self
when Lono::Configset::Register::Blueprint
Lono::Finder::Blueprint::Configset
when Lono::Configset::Register::Project
Lono::Finder::Configset
end
end
|
#jade_type ⇒ Object
26
27
28
|
# File 'lib/lono/configset/register/base.rb', line 26
def jade_type
finder_class.to_s.sub('Lono::Finder::','').underscore
end
|
#jadify ⇒ Object
19
20
21
22
23
24
|
# File 'lib/lono/configset/register/base.rb', line 19
def jadify
self.class.configsets.each do |registry|
jade = Lono::Jade.new(registry.name, jade_type, registry)
Lono::Jade::Registry.tracked_configsets << jade
end
end
|
#pretty_trace(caller_line) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/lono/configset/register/base.rb', line 82
def pretty_trace(caller_line)
md = caller_line.match(/(.*\.rb):(\d+):/)
path, error_line_number = md[1], md[2].to_i
context = 5
top, bottom = [error_line_number-context-1, 0].max, error_line_number+context-1
puts "Showing file: #{path}"
lines = IO.read(path).split("\n")
spacing = lines.size.to_s.size
lines[top..bottom].each_with_index do |line_content, index|
current_line_number = top+index+1
if current_line_number == error_line_number
printf("%#{spacing}d %s\n".color(:red), current_line_number, line_content)
else
printf("%#{spacing}d %s\n", current_line_number, line_content)
end
end
end
|
#register ⇒ Object
14
15
16
17
|
# File 'lib/lono/configset/register/base.rb', line 14
def register
evaluate
jadify
end
|
#show_errors_and_exit!(errors) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/lono/configset/register/base.rb', line 66
def show_errors_and_exit!(errors)
errors.each do |error_type, registry|
name, caller_line = registry.name, registry.caller_line
case error_type
when :finder_missing
puts "ERROR: Configset with name #{name} not found. Please double check Gemfile and configs/#{@blueprint}/configsets files.".color(:red)
pretty_trace(caller_line)
when :resource_missing
puts "ERROR: Configset with name #{name} does not specify resource. The resource key is required.".color(:red)
pretty_trace(caller_line)
raise
end
end
exit 1
end
|
#store_for_validation(registry) ⇒ Object
Store to be able to provide the validation errors altogether later.
41
42
43
44
45
46
47
48
|
# File 'lib/lono/configset/register/base.rb', line 41
def store_for_validation(registry)
caller_line = caller.grep(/evaluate_file/).first
registry.caller_line = caller_line
names = self.class.validations.map {|r| r.name }
self.class.validations << registry unless names.include?(registry.name)
end
|
#validate! ⇒ Object
Validate the configset before building templates. So user finds out about errors early.
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/lono/configset/register/base.rb', line 51
def validate!
errors = []
self.class.validations.each do |registry|
config = finder_class.find(registry.name)
errors << [:finder_missing, registry] unless config
if registry.depends_on.nil? && registry.resource.nil?
errors << [:resource_missing, registry]
end
end
return if errors.empty?
show_errors_and_exit!(errors)
end
|