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
rubocop:disable Style/OptionalBooleanParameter.
-
#initialize(source, key, options) ⇒ SettingValue
constructor
A new instance of SettingValue.
- #value ⇒ Object
- #value_by_constant ⇒ Object
- #value_by_constant? ⇒ Boolean
- #value_by_method ⇒ Object
- #value_by_method? ⇒ Boolean
- #value_by_settings_object ⇒ Object
- #value_by_settings_object? ⇒ Boolean
Methods included from EacRubyUtils::SimpleCache
#method_missing, #reset_cache, #respond_to_missing?, #sanitize_cache_key, uncached_method_name
Constructor Details
#initialize(source, key, options) ⇒ SettingValue
Returns a new instance of SettingValue.
18 19 20 21 22 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 18 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
rubocop:disable Style/OptionalBooleanParameter
24 25 26 27 28 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 24 def constant_name(fullname = false) # rubocop:disable Style/OptionalBooleanParameter name = key.to_s.underscore.upcase name = "#{source.class.name}::#{name}" if fullname name end |
#value ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 30 def value .order.each do |method| return send("value_by_#{method}") if send("value_by_#{method}?") end return .default if .respond_to?(OPTION_DEFAULT) return nil unless .required raise_key_not_found end |
#value_by_constant ⇒ Object
40 41 42 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 40 def value_by_constant source.class.const_get(constant_name) end |
#value_by_constant? ⇒ Boolean
44 45 46 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 44 def value_by_constant? source.class.const_defined?(constant_name) end |
#value_by_method ⇒ Object
48 49 50 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 48 def value_by_method source.send(key) end |
#value_by_method? ⇒ Boolean
52 53 54 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 52 def value_by_method? source.respond_to?(key, true) end |
#value_by_settings_object ⇒ Object
56 57 58 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 56 def value_by_settings_object source.settings_object.fetch(key) end |
#value_by_settings_object? ⇒ Boolean
60 61 62 |
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 60 def value_by_settings_object? source.settings_object.key?(key) end |