Class: Smartdict::Translator::DriverConfiguration
- Inherits:
-
Object
- Object
- Smartdict::Translator::DriverConfiguration
- Defined in:
- lib/smartdict/translator/driver_configuration.rb
Overview
Middleware
Instance Method Summary collapse
- #call(word, opts) ⇒ Object
- #define_driver(from_lang, to_lang) ⇒ Object
-
#initialize(translator) ⇒ DriverConfiguration
constructor
A new instance of DriverConfiguration.
Constructor Details
#initialize(translator) ⇒ DriverConfiguration
Returns a new instance of DriverConfiguration.
3 4 5 |
# File 'lib/smartdict/translator/driver_configuration.rb', line 3 def initialize(translator) @translator = translator end |
Instance Method Details
#call(word, opts) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/smartdict/translator/driver_configuration.rb', line 7 def call(word, opts) unless opts[:driver] opts[:driver] = define_driver(opts[:from_lang], opts[:to_lang]) end @translator.call(word, opts) end |
#define_driver(from_lang, to_lang) ⇒ Object
14 15 16 17 18 |
# File 'lib/smartdict/translator/driver_configuration.rb', line 14 def define_driver(from_lang, to_lang) key = "#{from_lang}-#{to_lang}" conf = configatron.drivers conf.retrieve(key) || conf.retrieve(:default) || raise(Smartdict::Error.new("No default driver")) end |