Class: EacRubyUtils::SettingsProvider::SettingValue
- Includes:
- Listable, EacRubyUtils::SimpleCache
- Defined in:
- lib/eac_ruby_utils/settings_provider/setting_value.rb
Constant Summary
Constants included from EacRubyUtils::SimpleCache
EacRubyUtils::SimpleCache::UNCACHED_METHOD_NAME_SUFFIX, EacRubyUtils::SimpleCache::UNCACHED_METHOD_PATTERN
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #constant_name(fullname = false) ⇒ Object
-
#initialize(source, key, options) ⇒ SettingValue
constructor
A new instance of SettingValue.
- #value ⇒ Object
- #value_by_constant ⇒ Object
- #value_by_method ⇒ Object
- #value_by_settings_object ⇒ Object
Methods included from EacRubyUtils::SimpleCache
#method_missing, #reset_cache, #respond_to_missing?, uncached_method_name
Constructor Details
#initialize(source, key, options) ⇒ SettingValue
Returns a new instance of SettingValue.
17 18 19 20 21 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 17 def initialize(source, key, ) @source = source @key = key @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class EacRubyUtils::SimpleCache
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
14 15 16 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 14 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 14 def @options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
14 15 16 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 14 def source @source end |
Instance Method Details
#constant_name(fullname = false) ⇒ Object
23 24 25 26 27 |
# 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 ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 29 def value .order.each do |method| value = send("value_by_#{method}") return value if value end return .default if .respond_to?(OPTION_DEFAULT) return nil unless .required raise_key_not_found end |
#value_by_constant ⇒ Object
40 41 42 43 44 |
# 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 ⇒ Object
46 47 48 |
# 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 ⇒ Object
50 51 52 |
# 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 |