Class: Arproxy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/arproxy/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



11
12
13
14
15
16
# File 'lib/arproxy/config.rb', line 11

def initialize
  @proxies = []
  if defined?(Rails)
    @adapter = Rails.application.config_for(:database)['adapter']
  end
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



8
9
10
# File 'lib/arproxy/config.rb', line 8

def adapter
  @adapter
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/arproxy/config.rb', line 8

def logger
  @logger
end

#proxiesObject (readonly)

Returns the value of attribute proxies.



9
10
11
# File 'lib/arproxy/config.rb', line 9

def proxies
  @proxies
end

Instance Method Details

#adapter_classObject

Raises:



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/arproxy/config.rb', line 37

def adapter_class
  raise Arproxy::Error, 'config.adapter must be set' unless @adapter
  case @adapter
  when String, Symbol
    eval "::ActiveRecord::ConnectionAdapters::#{camelized_adapter_name}Adapter"
  when Class
    @adapter
  else
    raise Arproxy::Error, "unexpected config.adapter: #{@adapter}"
  end
end

#plugin(name, *options) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/arproxy/config.rb', line 27

def plugin(name, *options)
  plugin_class = Plugin.get(name)

  if plugin_class.is_a?(Class) && plugin_class.ancestors.include?(Arproxy::Base)
    raise Arproxy::Error, "Error on loading a plugin `#{plugin_class.inspect}`: the superclass `Arproxy::Base` is no longer supported since Arproxy v1. Use `Arproxy::Proxy` instead. See: https://github.com/cookpad/arproxy/blob/main/UPGRADING.md"
  end

  use(plugin_class, *options)
end

#use(proxy_class, *options) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/arproxy/config.rb', line 18

def use(proxy_class, *options)
  if proxy_class.is_a?(Class) && proxy_class.ancestors.include?(Arproxy::Base)
    raise Arproxy::Error, "Error on loading a proxy `#{proxy_class.inspect}`: the superclass `Arproxy::Base` is no longer supported since Arproxy v1. Use `Arproxy::Proxy` instead. See: https://github.com/cookpad/arproxy/blob/main/UPGRADING.md"
  end

  ::Arproxy.logger.debug("Arproxy: Mounting #{proxy_class.inspect} (#{options.inspect})")
  @proxies << [proxy_class, options]
end