Class: Arproxy::Config
- Inherits:
-
Object
- Object
- Arproxy::Config
- Defined in:
- lib/arproxy/config.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
Instance Method Summary collapse
- #adapter_class ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #plugin(name, *options) ⇒ Object
- #use(proxy_class, *options) ⇒ Object
Constructor Details
#initialize ⇒ Config
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
#adapter ⇒ Object
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/arproxy/config.rb', line 8 def adapter @adapter end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/arproxy/config.rb', line 8 def logger @logger end |
#proxies ⇒ Object (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_class ⇒ Object
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, *) 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, *) 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, *) 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} (#{.inspect})") @proxies << [proxy_class, ] end |