Class: Ufo::Layering::Layer
Constant Summary
collapse
- @@shown_layers =
false
Instance Method Summary
collapse
#pretty_home, #pretty_path, #pretty_time
#logger
#layers, #post_layers, #pre_layers
Constructor Details
#initialize(task_definition) ⇒ Layer
Returns a new instance of Layer.
21
22
23
|
# File 'lib/ufo/layering/layer.rb', line 21
def initialize(task_definition)
@task_definition = task_definition
end
|
Instance Method Details
#add_ext!(paths) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/ufo/layering/layer.rb', line 64
def add_ext!(paths)
ext = "rb"
paths.map! do |path|
path = path.sub(/\/$/,'') if path.ends_with?('/')
"#{path}.rb"
end
paths
end
|
#full_layering ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/ufo/layering/layer.rb', line 35
def full_layering
all = layers.map { |layer| layer.sub(/\/$/,'') } all.inject([]) do |sum, layer|
sum += layer_levels(layer) unless layer.nil?
sum
end
end
|
#full_layers(dir) ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/ufo/layering/layer.rb', line 73
def full_layers(dir)
layers = full_layering.map do |layer|
"#{dir}/#{layer}"
end
role_layers = full_layering.map do |layer|
"#{dir}/#{@task_definition.role}/#{layer}" end
layers += role_layers
layers.map { |l| l.gsub('//','/') } end
|
#layer_levels(prefix = nil) ⇒ Object
adds prefix and to each layer pair that has base and Ufo.env. IE:
"#{prefix}/base"
"#{prefix}/#{Ufo.env}"
54
55
56
57
58
59
60
61
62
|
# File 'lib/ufo/layering/layer.rb', line 54
def layer_levels(prefix=nil)
levels = ["base", Ufo.env]
levels.map! do |i|
[prefix, i].reject(&:blank?).join('/')
end
levels.unshift(prefix) levels
end
|
#main_layers ⇒ Object
45
46
47
|
# File 'lib/ufo/layering/layer.rb', line 45
def main_layers
['']
end
|
#paths ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/ufo/layering/layer.rb', line 25
def paths
core = full_layers(".ufo/vars")
app = full_layers(".ufo/vars/#{Ufo.app}")
paths = core + app
add_ext!(paths)
paths.map! { |p| "#{Ufo.root}/#{p}" }
show_layers(paths)
paths
end
|
#show_layers(paths) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/ufo/layering/layer.rb', line 85
def show_layers(paths)
return if @@shown_layers
logger.info "Vars Layers:" if ENV['UFO_SHOW_ALL_LAYERS']
paths.each do |path|
show_layer = File.exist?(path) && logger.level <= Logger::DEBUG
logger.info " #{pretty_path(path)}" if show_layer || ENV['UFO_SHOW_ALL_LAYERS']
end
@@shown_layers = true
end
|