class Lono::Layering

Public Class Methods

new(config, options={}, env=Lono.env, root=Lono.root) click to toggle source
Calls superclass method Lono::AbstractBase::new
# File lib/lono/layering.rb, line 5
def initialize(config, options={}, env=Lono.env, root=Lono.root)
  super(options)
  # config can be params or variables
  @config, @options, @env, @root = config, options, env, root
  @requested = determine_requested
end

Public Instance Methods

always() click to toggle source
# File lib/lono/layering.rb, line 21
def always
  base = "#{@root}/configs/#{@blueprint}/#{@config}/base"
  env = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}"
  [base, env]
end
determine_requested() click to toggle source
# File lib/lono/layering.rb, line 52
def determine_requested
  # param is usually set from the convention. when set from convention stack name takes higher precedence
  config_key = @config.singularize.to_sym # param or variable
  @options[config_key] || @options[:config] || @stack
end
direct_layers() click to toggle source
# File lib/lono/layering.rb, line 38
def direct_layers
  if @requested.starts_with?('/')
    [@requested] # IE: absolute full path
  else
    ["#{@root}/#{@requested}"] # IE : relative path within lono project]
  end
end
locations() click to toggle source
# File lib/lono/layering.rb, line 12
def locations
  paths = always + requested
  layers = paths.map do |path|
    requested_file(path)
  end.compact
  print_layers(layers)
  layers
end
print_layers(layers) click to toggle source
requested() click to toggle source
# File lib/lono/layering.rb, line 27
def requested
  standard_layers + direct_layers
end
requested_file(path) click to toggle source
# File lib/lono/layering.rb, line 58
def requested_file(path)
  # List of paths to consider from initial path provided. Combine params and variables possible paths for simplicity.
  paths = [path, "#{path}.txt", "#{path}.sh", "#{path}.rb"].compact
  paths.find { |p| File.file?(p) }
end
standard_layers() click to toggle source
# File lib/lono/layering.rb, line 31
def standard_layers
  config_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@requested}"
  env_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@requested}"
  template_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@template}/#{@requested}"
  [config_level, env_level, template_level]
end