Class: DAF::Option

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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



124
125
126
# File 'lib/daf/configurable.rb', line 124

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



124
125
126
# File 'lib/daf/configurable.rb', line 124

def type
  @type
end

#valueObject

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

Returns:

  • (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