class EacRubyUtils::SettingsProvider::SettingValue

Attributes

key[R]
options[R]
source[R]

Public Class Methods

new(source, key, options) click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 17
def initialize(source, key, options)
  @source = source
  @key = key
  @options = options
end

Public Instance Methods

constant_name(fullname = false) click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 23
def constant_name(fullname = false)
  name = key.to_s.underscore.upcase
  name = "#{source.class.name}::#{name}" if fullname
  name
end
value() click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 29
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
value_by_constant() click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 40
def value_by_constant
  source.class.const_get(constant_name)
rescue NameError
  nil
end
value_by_method() click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 46
def value_by_method
  source.respond_to?(key, true) ? source.send(key) : nil
end
value_by_settings_object() click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 50
def value_by_settings_object
  source.settings_object[key.to_s] || source.settings_object[key.to_sym]
end

Private Instance Methods

parsed_options_uncached() click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 56
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
raise_key_not_found() click to toggle source
# File lib/eac_ruby_utils/settings_provider/setting_value.rb, line 63
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