class Staticd::Models::StaticdConfig
Dynamic Staticd
configuration.
Manage all configuration parameters for Staticd
aimed to change during the application runtime.
Public Class Methods
ask_value?(name)
click to toggle source
Get the parameter boolean value associed with its value.
Convert boolean string into boolean value.
Example:
if Staticd::Models::StaticdConfig.ask_value?(:enable_god_mode) puts "God mode is enabled!" else puts "God mode is disabled!" end
# File lib/staticd/models/staticd_config.rb, line 55 def self.ask_value?(name) boolean_string = get_value(name) case boolean_string when "true" then true when "false" then false when nil then false else raise "Cannot convert a string into a boolean value" end end
get_value(name)
click to toggle source
Get a value for a parameter.
Return nil if no parameter with this name exist.
Example:
Staticd::Models::StaticdConfig.get_value(:foo)
# File lib/staticd/models/staticd_config.rb, line 40 def self.get_value(name) name = name.to_s (param = get(name)) ? param.value : nil end
set_value(name, value)
click to toggle source
Set a value for a parameter.
If the parameter exist, its value is updated otherwise the parameter is created with the privided value.
Example:
Staticd::Models::StaticdConfig.set_value(:foo, "bar")
# File lib/staticd/models/staticd_config.rb, line 23 def self.set_value(name, value) name = name.to_s value = value.to_s if (param = get(name)) param.update(value: value) else create(name: name, value: value) end value end
Public Instance Methods
to_s()
click to toggle source
# File lib/staticd/models/staticd_config.rb, line 66 def to_s "#{name}: #{value}" end