Class: Yacl::Loader

Inherits:
Object
  • Object
show all
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.

Defined Under Namespace

Classes: Env, Error, YamlDir, YamlFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#optionsObject (readonly)

Internal: The options object this loader is associated with



23
24
25
# File 'lib/yacl/loader.rb', line 23

def options
  @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( options, key = 'path' )
  ps = options[key.to_sym] || options[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

#propertiesObject

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_propertiesObject

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