lib/lono/layering.rb in lono-7.5.2 vs lib/lono/layering.rb in lono-8.0.0.pre.rc1

- old
+ new

@@ -1,65 +1,23 @@ -module Lono - class Layering < AbstractBase - extend Memoist +require "active_support/lazy_load_hooks" - 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 +module Lono + module Layering + def layers + pre_layers + main_layers + post_layers end - def locations - paths = always + requested - layers = paths.map do |path| - requested_file(path) - end.compact - print_layers(layers) - layers + def main_layers + super end - def always - base = "#{@root}/configs/#{@blueprint}/#{@config}/base" - env = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}" - [base, env] + def pre_layers + [] end - def requested - standard_layers + direct_layers + def post_layers + [] end - - 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 - - def direct_layers - if @requested.starts_with?('/') - [@requested] # IE: absolute full path - else - ["#{@root}/#{@requested}"] # IE : relative path within lono project] - end - end - - def print_layers(layers) - return unless ENV["LONO_DEBUG_LAYERING"] - puts "layers #{@config}:" - pp layers - end - - 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 - - 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 - memoize :requested_file end end + +ActiveSupport.run_load_hooks(:lono_layering, Lono::Layering)