Class: UnifiedSettings::Handlers::Constants
- Inherits:
-
Base
- Object
- Base
- UnifiedSettings::Handlers::Constants
show all
- Defined in:
- lib/unified_settings/handlers/constants.rb
Overview
Setting handler for Ruby constants
Constant Summary
collapse
- CONSTANT_KEY_NESTING_SEPARATOR =
'::'
Constants inherited
from Base
Base::KEY_NESTING_SEPARATOR
Instance Method Summary
collapse
Instance Method Details
#defined?(key, case_sensitive: nil) ⇒ Boolean
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/unified_settings/handlers/constants.rb', line 11
def defined?(key, case_sensitive: nil)
klass, variable_names = key_to_class_and_variable(
key, case_sensitive:
)
variable_names.each do |name|
if klass
return true if klass.const_defined?(name)
elsif Object.const_defined?(name)
return true
end
rescue NameError
end
false
end
|
#get(key, case_sensitive: nil) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/unified_settings/handlers/constants.rb', line 29
def get(key, case_sensitive: nil)
klass, variable_names = key_to_class_and_variable(
key, case_sensitive:
)
variable_names.each do |name|
return klass.const_get(name) if klass
return Object.const_get(name)
rescue NameError
end
nil
end
|