Class: ConfigToolkit::BaseConfig::ParamSpec
- Inherits:
-
Object
- Object
- ConfigToolkit::BaseConfig::ParamSpec
- Defined in:
- lib/configtoolkit/baseconfig.rb
Overview
This class represents the specification for a parameter. Right now, a parameter specification consists of:
-
The parameter name (Symbol)
-
The parameter value class (Class); values must be instances of this class or a child class.
-
Whether or not the parameter is required
-
If the parameter is not required, a default value
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#name ⇒ Object
readonly
:nodoc:.
-
#value_class ⇒ Object
readonly
Returns the value of attribute value_class.
Instance Method Summary collapse
-
#default_value? ⇒ Boolean
Returns: true if and only if the parameter has a default value.
-
#initialize(name, value_class, is_required, default_value) ⇒ ParamSpec
constructor
Description: This constructs a ParamSpec for parameter name and value of class value_class.
-
#required? ⇒ Boolean
Returns: true if and only if the parameter must be set in a configuration file; false otherwise.
Constructor Details
#initialize(name, value_class, is_required, default_value) ⇒ ParamSpec
Description:
This constructs a ParamSpec for parameter name and value of class value_class. If is_required, then the parameter is required; otherwise, the parameter is optional with a default value of default_value.
Parameters:
- name
-
The name of the parameter
- value_class
-
The class of the parameter’s values
- is_required
-
Whether or not the parameter must be set in a configuration file
- default_value
-
If the parameter need not be set in a configuration file (!is_required), the value it defaults to if it’s not specified. A default_value of BaseConfig::NO_DEFAULT_VALUE means that there is no default_value attribute.
96 97 98 99 100 101 |
# File 'lib/configtoolkit/baseconfig.rb', line 96 def initialize(name, value_class, is_required, default_value) @name = name @value_class = value_class @is_required = is_required @default_value = default_value end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
73 74 75 |
# File 'lib/configtoolkit/baseconfig.rb', line 73 def default_value @default_value end |
#name ⇒ Object (readonly)
:nodoc:
71 72 73 |
# File 'lib/configtoolkit/baseconfig.rb', line 71 def name @name end |
#value_class ⇒ Object (readonly)
Returns the value of attribute value_class.
72 73 74 |
# File 'lib/configtoolkit/baseconfig.rb', line 72 def value_class @value_class end |
Instance Method Details
#default_value? ⇒ Boolean
Returns:
true if and only if the parameter has a default value
107 108 109 |
# File 'lib/configtoolkit/baseconfig.rb', line 107 def default_value? return !@default_value.equal?(BaseConfig::NO_DEFAULT_VALUE) end |
#required? ⇒ Boolean
Returns:
true if and only if the parameter must be set in a configuration file; false otherwise.
116 117 118 |
# File 'lib/configtoolkit/baseconfig.rb', line 116 def required? return @is_required end |