Class: Confection::Project
- Inherits:
-
Object
- Object
- Confection::Project
- Includes:
- Enumerable
- Defined in:
- lib/confection/project.rb
Overview
Rename to ‘ProjectConfig` or ?
Project configuration.
Constant Summary collapse
- 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`
'{.,}config{.rb,}'
Instance Attribute Summary collapse
-
#root ⇒ String
(also: #directory)
readonly
Project root directory.
Class Method Summary collapse
-
.cache ⇒ Object
Per library cache.
-
.load(lib = nil) ⇒ Project?
Get project configuration from another library.
-
.lookup(dir = nil) ⇒ String
Lookup configuation file.
Instance Method Summary collapse
-
#controller(scope, tool, options = {}) ⇒ Object
Create a configuration controller.
-
#each(&block) ⇒ Object
Iterate over each configurations.
-
#initialize(root) ⇒ Project
constructor
Initialize new ProjectConfig.
-
#profiles(tool) ⇒ Array
List of configuration profiles.
-
#properties ⇒ Object
Project properties.
-
#size ⇒ Fixnum
The number of configurations.
-
#source ⇒ String
The file path of the project’s configuration file.
-
#store ⇒ Object
Configuration store tracks a project’s confirguration entries.
Constructor Details
Instance Attribute Details
#root ⇒ String (readonly) Also known as: directory
Project root directory.
91 92 93 |
# File 'lib/confection/project.rb', line 91 def root @root end |
Class Method Details
.cache ⇒ Object
Per library cache.
29 30 31 |
# File 'lib/confection/project.rb', line 29 def self.cache @cache ||= {} end |
.load(lib = nil) ⇒ Project?
Get project configuration from another library.
This method uses the Finder gem.
43 44 45 46 47 48 49 50 51 52 53 54 |
# 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(dir = nil) ⇒ String
Lookup configuation file.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/confection/project.rb', line 64 def self.lookup(dir=nil) dir = dir || Dir.pwd home = File.('~') 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 |
Instance Method Details
#controller(scope, tool, options = {}) ⇒ Object
Create a configuration controller.
147 148 149 150 151 |
# File 'lib/confection/project.rb', line 147 def controller(scope, tool, ={}) profile = [:profile] configs = store.lookup(tool, profile) Controller.new(scope, *configs) end |
#each(&block) ⇒ Object
Iterate over each configurations.
156 157 158 |
# File 'lib/confection/project.rb', line 156 def each(&block) store.each(&block) end |
#profiles(tool) ⇒ Array
List of configuration profiles.
119 120 121 |
# File 'lib/confection/project.rb', line 119 def profiles(tool) store.profiles(tool) end |
#properties ⇒ Object
Use cascading class, e.g. Confstruct.
Project properties.
128 129 130 131 132 133 134 135 136 |
# 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 |
#size ⇒ Fixnum
The number of configurations.
165 166 167 |
# File 'lib/confection/project.rb', line 165 def size store.size end |