Class: DAF::Option
- Inherits:
-
Object
- Object
- DAF::Option
- Defined in:
- lib/daf/configurable.rb
Overview
Used to store options - includes the expected type the name, and the value. Also includes validation logic
-
the absence of validation logic in the value= operator is
intentional, as there may be cases where you can set an invalid option value
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, type, verifier = nil) ⇒ Option
constructor
A new instance of Option.
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, type, verifier = nil) ⇒ Option
Returns a new instance of Option.
127 128 129 130 131 132 133 134 135 |
# File 'lib/daf/configurable.rb', line 127 def initialize(name, type, verifier = nil) @type = type @name = name @verifier = if verifier verifier else true end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
124 125 126 |
# File 'lib/daf/configurable.rb', line 124 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
124 125 126 |
# File 'lib/daf/configurable.rb', line 124 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
125 126 127 |
# File 'lib/daf/configurable.rb', line 125 def value @value end |
Instance Method Details
#valid? ⇒ Boolean
137 138 139 140 |
# File 'lib/daf/configurable.rb', line 137 def valid? !@value.nil? && @value.is_a?(@type) && (@verifier == true || @verifier.call(@value)) end |