class CFA::BooleanValue
Represents a boolean value switcher in default grub configuration file. Allows easy switching and questioning for boolean value, even if represented by text in config file. It's tristate: if unset, {#enabled?} and {#disabled?} return `nil` (but once set, we cannot return to an unset state).
Public Class Methods
new(name, model, true_value: "true", false_value: "false")
click to toggle source
@param name [String] @param model [BaseModel] @param true_value [String] @param false_value [String]
# File lib/cfa/base_model.rb, line 179 def initialize(name, model, true_value: "true", false_value: "false") @name = name @model = model @true_value = true_value @false_value = false_value end
Public Instance Methods
defined?()
click to toggle source
@return [Boolean]
true if the key has a value; false if {#enabled?} and {#disabled?} return `nil`.
# File lib/cfa/base_model.rb, line 215 def defined? !data.nil? end
disable()
click to toggle source
Set to false
# File lib/cfa/base_model.rb, line 192 def disable @model.generic_set(@name, @false_value) end
disabled?()
click to toggle source
@return [Boolean,nil] true, false, (nil if undefined)
# File lib/cfa/base_model.rb, line 205 def disabled? d = data return nil unless d d != @true_value end
enable()
click to toggle source
Set to true
# File lib/cfa/base_model.rb, line 187 def enable @model.generic_set(@name, @true_value) end
enabled?()
click to toggle source
@return [Boolean,nil] true, false, (nil if undefined)
# File lib/cfa/base_model.rb, line 197 def enabled? d = data return nil unless d d == @true_value end
inspect()
click to toggle source
enhanced inspect method to contain important data
# File lib/cfa/base_model.rb, line 227 def inspect "#<CFA::BooleanValue:0x#{object_id} name=#{@name.inspect}, " \ "data=#{data.inspect}, true_value=#{@true_value.inspect}, " \ "false_value=#{@false_value.inspect}>" end
Also aliased as: to_s
value=(value)
click to toggle source
sets boolean value, recommend to use for generic boolean setter. for constants prefer to use enable/disable @param value [Boolean]
# File lib/cfa/base_model.rb, line 222 def value=(value) @model.generic_set(@name, value ? @true_value : @false_value) end
Private Instance Methods
data()
click to toggle source
# File lib/cfa/base_model.rb, line 238 def data @model.generic_get(@name) end