module CConfig::HashUtils::Extensions
Extensions
contains the methods to be provided for each hash object produced by this gem.
Attributes
defaults[RW]
Public Instance Methods
default_of(key)
click to toggle source
Returns the default value of the given key. Note that this key can specify nested values with the period notation (e.g. “a.b”).
# File lib/cconfig/hash_utils.rb, line 55 def default_of(key) cur = defaults key.split(".").each do |part| cur = cur[part] break if cur.nil? end cur end
disabled?(feature)
click to toggle source
Returns true if the given feature is disabled or doesn't exist. This is a shorthand for `!enabled?`.
# File lib/cconfig/hash_utils.rb, line 49 def disabled?(feature) !enabled?(feature) end
enabled?(feature)
click to toggle source
Returns true if the given feature is enabled, false otherwise. This also works in embedded configuration values. For example: enabled?(“a.b”) will return true for:
a: b: enabled: true
# File lib/cconfig/hash_utils.rb, line 35 def enabled?(feature) cur = self parts = feature.split(".") parts.each do |part| cur = cur[part] return false if !cur || cur.empty? end cur.key?("enabled") && cur["enabled"].eql?(true) end