Class: Yacl::Define::Defaults

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yacl/define/defaults.rb

Overview

Public: A base class for use in defining your application’s default configuration properties.

For the API purposes, classes that inherit from Defaults may behave as both Loader and Properties classes.

Examples:

class MyDefaults < Yacl::Define::Defaults
  default 'host.name', 'localhost'
  default 'host.port', 4321
end

Now you can use an instances of MyDefaults to find your defaults

d = MyDefaults.new
d.host.name               # => 'localhost'

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Defaults

Internal: Fake out being a Loader.

This method is here to implement the LoaderAPI

Returns nothing.



54
55
56
# File 'lib/yacl/define/defaults.rb', line 54

def initialize( opts = {} )
  @properties = self.class.properties
end

Instance Attribute Details

#propertiesObject (readonly)

Internal: Return the Properties so we behave like a Loader



47
48
49
# File 'lib/yacl/define/defaults.rb', line 47

def properties
  @properties
end

Class Method Details

.default(name, value) ⇒ Object

Public: Define a property and its value.

name - The String name of the property. value - The obj to be the default value for the given name.

Returns nothing.



37
38
39
40
41
# File 'lib/yacl/define/defaults.rb', line 37

def self.default( name, value )
  args = name.to_s.split('.')
  args << value
  properties.set( *args )
end

.propertiesObject

Internal: Create the instance of Properties that will be populated by calls to Properties::default.

Returns: Properties



27
28
29
# File 'lib/yacl/define/defaults.rb', line 27

def self.properties
  @properties ||= ::Yacl::Properties.new
end