Class: EacRubyUtils::SettingsProvider::SettingValue
Constant Summary
EacRubyUtils::SimpleCache::UNCACHED_METHOD_NAME_SUFFIX, EacRubyUtils::SimpleCache::UNCACHED_METHOD_PATTERN
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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.
17
18
19
20
21
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 17
def initialize(source, key, options)
@source = source
@key = key
@options = options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class EacRubyUtils::SimpleCache
Instance Attribute Details
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
|
Returns the value of attribute options.
14
15
16
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 14
def options
@options
end
|
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
|
29
30
31
32
33
34
35
36
37
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 29
def value
parsed_options.order.each do |method|
return send("value_by_#{method}") if send("value_by_#{method}?")
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 ⇒ Object
39
40
41
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 39
def value_by_constant
source.class.const_get(constant_name)
end
|
#value_by_constant? ⇒ Boolean
43
44
45
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 43
def value_by_constant?
source.class.const_defined?(constant_name)
end
|
#value_by_method ⇒ Object
47
48
49
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 47
def value_by_method
source.send(key)
end
|
#value_by_method? ⇒ Boolean
51
52
53
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 51
def value_by_method?
source.respond_to?(key, true)
end
|
#value_by_settings_object ⇒ Object
55
56
57
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 55
def value_by_settings_object
source.settings_object.fetch(key)
end
|
#value_by_settings_object? ⇒ Boolean
59
60
61
|
# File 'lib/eac_ruby_utils/settings_provider/setting_value.rb', line 59
def value_by_settings_object?
source.settings_object.key?(key)
end
|