Class: Kubes::Compiler
Defined Under Namespace
Modules: Decorator, Layering, Shared, Util
Classes: Strategy
Instance Method Summary
collapse
#config_skip?, #files, #filter_skip, #index_for, #process?, #search_expr, #sorted_files, #two_levels_deep?
#consider?
Methods included from Logging
#logger
#run_hooks
Constructor Details
#initialize(options = {}) ⇒ Compiler
Returns a new instance of Compiler.
8
9
10
|
# File 'lib/kubes/compiler.rb', line 8
def initialize(options={})
@options = options
end
|
Instance Method Details
#pretty(path) ⇒ Object
72
73
74
|
# File 'lib/kubes/compiler.rb', line 72
def pretty(path)
path.sub("#{Kubes.root}/",'')
end
|
#resources ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/kubes/compiler.rb', line 30
def resources
paths = []
expr = "#{Kubes.root}/.kubes/resources/**/*"
Dir.glob(expr).each do |path|
next unless process?(path)
paths << path
end
paths
end
|
#run ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/kubes/compiler.rb', line 12
def run
Kubes.config run_hooks("kubes.rb", name: "compile") do
results = resources.map do |path|
strategy = Strategy.new(@options.merge(path: path))
strategy.compile
end.compact
results.each do |result|
write(result)
end
end
write_full
logger.info "Compiled .kubes/resources files to .kubes/output" if show_compiled_message?
end
|
#show_compiled_message? ⇒ Boolean
68
69
70
|
# File 'lib/kubes/compiler.rb', line 68
def show_compiled_message?
!%w[g ge get].include?(ARGV.first)
end
|
#write(result) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/kubes/compiler.rb', line 40
def write(result)
return if config_skip?(result.filename)
return if result.skip?
result.decorate!(:post)
filename, content = result.filename, result.content
dest = "#{Kubes.root}/.kubes/output/#{filename}"
if result.io?
FileUtils.cp(filename, dest) else
FileUtils.mkdir_p(File.dirname(dest))
IO.write(dest, content)
end
logger.debug "Written #{pretty(dest)}"
end
|
#write_full ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/kubes/compiler.rb', line 57
def write_full
full = sorted_files.inject([]) do |acc, file|
acc << IO.read(file)
end
content = full.join("\n")
path = "#{Kubes.root}/.kubes/tmp/full.yaml" FileUtils.mkdir_p(File.dirname(path))
IO.write(path, content)
logger.debug "Written #{pretty(path)}"
end
|