Class: ComplexConfig::Proxy
- Inherits:
- BasicObject
- Defined in:
- lib/complex_config/proxy.rb
Overview
A proxy class that provides dynamic configuration access with lazy evaluation
The Proxy class acts as a wrapper around configuration access, deferring the actual configuration loading until a method is first called. It supports environment-specific configuration lookups and can handle both direct configuration access and existence checks.
lookups
Instance Attribute Summary collapse
-
#env ⇒ String?
readonly
The environment name used for configuration.
Instance Method Summary collapse
-
#initialize(env = nil) ⇒ Proxy
constructor
The proxy object’s initialization method sets up the environment for configuration access.
-
#inspect ⇒ String
The inspect method returns a string representation of the proxy object.
-
#method_missing(name, *args) ⇒ Object
The method_missing method handles dynamic configuration access and validation.
-
#reload ⇒ ComplexConfig::Proxy
The reload method flushes the configuration cache and returns the receiver.
-
#to_s ⇒ String
The to_s method returns a string representation of the proxy object.
Constructor Details
#initialize(env = nil) ⇒ Proxy
The proxy object’s initialization method sets up the environment for configuration access.
18 19 20 |
# File 'lib/complex_config/proxy.rb', line 18 def initialize(env = nil) @env = env end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
The method_missing method handles dynamic configuration access and validation.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/complex_config/proxy.rb', line 52 def method_missing(name, *args) if name =~ /\?\z/ method_name, name = name, $` exist = ::ComplexConfig::Provider.exist?(name) (class << self; self; end).class_eval do define_method(method_name) do |env = nil| if exist __send__(name, *args) else nil end end end __send__(method_name, *args) else config = ::ComplexConfig::Provider[name] (class << self; self; end).class_eval do define_method(name) do |env = nil| if env ||= @env config[env] || ::ComplexConfig::Settings.new else config end end end __send__(name, *args) end end |
Instance Attribute Details
#env ⇒ String? (readonly)
The environment name used for configuration
12 13 14 |
# File 'lib/complex_config/proxy.rb', line 12 def env @env end |
Instance Method Details
#inspect ⇒ String
The inspect method returns a string representation of the proxy object.
32 33 34 |
# File 'lib/complex_config/proxy.rb', line 32 def inspect "#<#{to_s}>" end |
#reload ⇒ ComplexConfig::Proxy
The reload method flushes the configuration cache and returns the receiver.
40 41 42 43 |
# File 'lib/complex_config/proxy.rb', line 40 def reload ::ComplexConfig::Provider.flush_cache self end |
#to_s ⇒ String
The to_s method returns a string representation of the proxy object.
25 26 27 |
# File 'lib/complex_config/proxy.rb', line 25 def to_s 'ComplexConfig::Proxy' end |