Class: Yacl::Loader
- Inherits:
-
Object
- Object
- Yacl::Loader
- Defined in:
- lib/yacl/loader.rb,
lib/yacl/loader/env.rb,
lib/yacl/loader/yaml_dir.rb,
lib/yacl/loader/yaml_file.rb
Overview
Loader - the base class of all Loaders. It defines the Loader API>
The Loader API is:
1) The initializer method takes an Hash. This hash is stored in the
@options and is avaialble to all child clasess via the #options
method.
2) The #properties method takes no parameters and MUST return a Properties
instance
3) If the options passed into the initializer has a :reference_properites
key, its value is made available via the #reference_properties method.
Loader also provides a couple of utility methods for use by child classes.
Direct Known Subclasses
Define::Cli::Options, Define::Cli::Parser, Env, YamlDir, YamlFile
Defined Under Namespace
Classes: Env, Error, YamlDir, YamlFile
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Internal: The options object this loader is associated with.
Class Method Summary collapse
-
.extract_path(options, key = 'path') ⇒ Object
Internal: Extract the value from :path and covert it to a Pathname If a :path key is found, then extract it and convert the value to a Pathname.
-
.mapify_key(param) ⇒ Object
Internal: Return param split on “.”.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Loader
constructor
Create a new instance of the Loader.
-
#properties ⇒ Object
Internal:.
-
#reference_properties ⇒ Object
Internal:.
Constructor Details
#initialize(opts = {}) ⇒ Loader
Create a new instance of the Loader
opts - as Hash of options. Well known options are:
:properties - A Properties object
:path - A directory/file path
31 32 33 |
# File 'lib/yacl/loader.rb', line 31 def initialize( opts = {} ) @options = opts end |
Instance Attribute Details
#options ⇒ Object (readonly)
Internal: The options object this loader is associated with
23 24 25 |
# File 'lib/yacl/loader.rb', line 23 def @options end |
Class Method Details
.extract_path(options, key = 'path') ⇒ Object
Internal: Extract the value from :path and covert it to a Pathname If a :path key is found, then extract it and convert the value to a Pathname
options - a Hash key = the key to extract as a path (default: ‘path’)
Returns a Pathname or nil.
71 72 73 74 75 |
# File 'lib/yacl/loader.rb', line 71 def self.extract_path( , key = 'path' ) ps = [key.to_sym] || [key.to_s] return nil unless ps return Pathname.new( ps ) end |
.mapify_key(param) ⇒ Object
Internal: Return param split on “.”
This will only be done if param is a String
Returns an Array or param
58 59 60 61 |
# File 'lib/yacl/loader.rb', line 58 def self.mapify_key( param ) return param unless param.kind_of?( String ) return param.split('.') end |
Instance Method Details
#properties ⇒ Object
Internal:
Load the properties according to the type of loader it is
Returns: Properties
40 41 42 |
# File 'lib/yacl/loader.rb', line 40 def properties Properties.new end |
#reference_properties ⇒ Object
Internal:
The properties that are passed in to use should we need them while loading
Returns: properties
49 50 51 |
# File 'lib/yacl/loader.rb', line 49 def reference_properties @options[:properties] end |