class EacRubyUtils::SettingsProvider::SettingValue
def constant_name(fullname = false)
def constant_name(fullname = false) name = key.to_s.underscore.upcase name = "#{source.class.name}::#{name}" if fullname name end
def initialize(source, key, options)
def initialize(source, key, options) @source = source @key = key @options = options end
def parsed_options_uncached
def parsed_options_uncached r = self.class.lists.option.hash_keys_validate!(options.symbolize_keys) r[:required] = true unless r.key?(OPTION_REQUIRED) r[:order] = source.setting_search_order if r[OPTION_ORDER].nil? ::EacRubyUtils::Struct.new(r) end
def raise_key_not_found
def raise_key_not_found raise "Setting \"#{key}\" not found. Supply in #{source.settings_object_name}, implement "\ "a \"#{key}\" method or declare a #{constant_name(true)} constant." end
def value
def value parsed_options.order.each do |method| value = send("value_by_#{method}") return value if value end return parsed_options.default if parsed_options.respond_to?(OPTION_DEFAULT) return nil unless parsed_options.required raise_key_not_found end
def value_by_constant
def value_by_constant source.class.const_get(constant_name) rescue NameError nil end
def value_by_method
def value_by_method source.respond_to?(key, true) ? source.send(key) : nil end
def value_by_settings_object
def value_by_settings_object source.settings_object[key.to_s] || source.settings_object[key.to_sym] end