Class: ActiveMatrix::Bot::MultiInstanceBase::SettingsProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_matrix/bot/multi_instance_base.rb

Overview

Settings proxy to merge class and instance settings

Instance Method Summary collapse

Constructor Details

#initialize(base_settings, agent_settings) ⇒ SettingsProxy

Returns a new instance of SettingsProxy.



165
166
167
168
# File 'lib/active_matrix/bot/multi_instance_base.rb', line 165

def initialize(base_settings, agent_settings)
  @base_settings = base_settings
  @agent_settings = agent_settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/active_matrix/bot/multi_instance_base.rb', line 170

def method_missing(method, *, &)
  method_name = method.to_s.gsub(/\?$/, '')

  # Check agent settings first
  if @agent_settings.key?(method_name)
    value = @agent_settings[method_name]
    return method.to_s.end_with?('?') ? !value.nil? : value
  end

  # Fall back to base settings
  @base_settings.send(method, *, &)
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


183
184
185
186
# File 'lib/active_matrix/bot/multi_instance_base.rb', line 183

def respond_to_missing?(method, include_private = false)
  method_name = method.to_s.gsub(/\?$/, '')
  @agent_settings.key?(method_name) || @base_settings.respond_to?(method, include_private)
end