lib/figgy/configuration.rb in figgy-0.9.0 vs lib/figgy/configuration.rb in figgy-0.9.1

- old
+ new

@@ -1,9 +1,9 @@ class Figgy class Configuration - # The directory in which to search for configuration files - attr_reader :root + # The directories in which to search for configuration files + attr_reader :roots # The list of defined overlays attr_reader :overlays # Whether to reload a configuration file each time it is accessed @@ -19,11 +19,11 @@ # Constructs a new {Figgy::Configuration Figgy::Configuration} instance. # # By default, uses a +root+ of the current directory, and defines handlers # for +.yml+, +.yaml+, +.yml.erb+, +.yaml.erb+, and +.json+. def initialize - self.root = Dir.pwd + @roots = [Dir.pwd] @handlers = [] @overlays = [] @always_reload = false @preload = false @freeze = false @@ -41,13 +41,17 @@ JSON.parse(contents) end end def root=(path) - @root = File.expand_path(path) + @roots = [File.expand_path(path)] end + def add_root(path) + @roots.unshift File.expand_path(path) + end + # @see #always_reload= def always_reload? !!@always_reload end @@ -86,11 +90,13 @@ @overlays << [combined_name, value] end # @return [Array<String>] the list of directories to search for config files def overlay_dirs - return [@root] if @overlays.empty? - overlay_values.map { |v| v ? File.join(@root, v) : @root }.uniq + return @roots if @overlays.empty? + overlay_values.map { |overlay| + @roots.map { |root| overlay ? File.join(root, overlay) : root } + }.flatten.uniq end # Adds a new handler for files with any extension in +extensions+. # # @example Adding an XML handler