class Confection::Project
Project
configuration.
@todo Rename to ‘ProjectConfig` or ?
Constants
- PATTERN
Configuration file pattern. The standard configuration file name is ‘Config.rb`, and that name should be used in most cases. However, `.config.rb` can also be use and will take precedence if found. Conversely, `config.rb` (lowercase form) can also be used but has the least precedence.
Config
files looked for in the order or precedence:* `.config.rb` * `Config.rb` * `config.rb`
Attributes
Project
root directory.
@return [String] project’s root directory
Project
root directory.
@return [String] project’s root directory
Public Class Methods
Per library cache.
# File lib/confection/project.rb, line 29 def self.cache @cache ||= {} end
Get project configuration from another library.
This method uses the Finder gem.
@param [String] lib
Library name.
@return [Project,nil] Located project.
# File lib/confection/project.rb, line 43 def self.load(lib=nil) if lib lib = lib.to_s return cache[lib] if cache.key?(lib) cache[lib] ||= ( config_path = Find.path(PATTERN, :from=>lib).first config_path ? new(File.dirname(config_path)) : nil ) else lookup end end
Lookup configuation file.
@param dir [String]
Optional directory to begin search.
@return [String] file path
# File lib/confection/project.rb, line 64 def self.lookup(dir=nil) dir = dir || Dir.pwd home = File.expand_path('~') while dir != '/' && dir != home if file = Dir.glob(File.join(dir, PATTERN), File::FNM_CASEFOLD).first return new(File.dirname(file)) end dir = File.dirname(dir) end return nil end
Initialize new ProjectConfig.
@param [String] root
Project root directory.
# File lib/confection/project.rb, line 82 def initialize(root) @root = root end
Public Instance Methods
Create a configuration controller.
@param [Object] scope
Context for which controller is being created.
@param [Symbol] tool
The tool of the configuration to select.
# File lib/confection/project.rb, line 147 def controller(scope, tool, options={}) profile = options[:profile] configs = store.lookup(tool, profile) Controller.new(scope, *configs) end
Iterate over each configurations.
# File lib/confection/project.rb, line 156 def each(&block) store.each(&block) end
List of configuration profiles.
@return [Array] profile names
# File lib/confection/project.rb, line 119 def profiles(tool) store.profiles(tool) end
Project
properties.
@todo Use cascading class, e.g. Confstruct.
# File lib/confection/project.rb, line 128 def properties dotruby = File.join(directory,'.ruby') if File.exist?(dotruby) data = YAML.load_file(dotruby) OpenStruct.new(data) else OpenStruct.new end end
The number of configurations.
@return [Fixnum] config count
# File lib/confection/project.rb, line 165 def size store.size end
The file path of the project’s configuration file.
@return [String] path to configuration file
# File lib/confection/project.rb, line 110 def source Dir.glob(File.join(root, PATTERN), File::FNM_CASEFOLD) end
Configuration store tracks a project’s confirguration entries.
# File lib/confection/project.rb, line 101 def store @store ||= Store.new(*source) end