Module: AnywayAppConfig::Singleton::ClassMethods
- Defined in:
- lib/anyway_app_config/singleton.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/anyway_app_config/singleton.rb', line 34
def method_missing(method_name, ...)
if instance.respond_to?(method_name)
instance.public_send(method_name, ...)
else
super
end
end
|
Instance Method Details
#instance ⇒ Object
24
25
26
27
28
|
# File 'lib/anyway_app_config/singleton.rb', line 24
def instance
return @instance if instance_variable_defined?(:@instance) && @instance
raise NotLoadedError, "#{name || self} is not loaded; call #{name || self}.load! first"
end
|
#load! ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/anyway_app_config/singleton.rb', line 12
def load!(*, **)
if instance_variable_defined?(:@instance) && @instance
raise AlreadyLoadedError, "#{name || self} is already loaded"
end
@instance = new(*, **).tap(&:deep_freeze_values!)
end
|
#loaded? ⇒ Boolean
20
21
22
|
# File 'lib/anyway_app_config/singleton.rb', line 20
def loaded?
instance_variable_defined?(:@instance) && !@instance.nil?
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/anyway_app_config/singleton.rb', line 30
def respond_to_missing?(method_name, include_private = false)
(loaded? && @instance.respond_to?(method_name, include_private)) || super
end
|