Class: Droonga::AdapterRunner
- Inherits:
-
Object
- Object
- Droonga::AdapterRunner
- Includes:
- Loggable
- Defined in:
- lib/droonga/adapter_runner.rb
Instance Method Summary collapse
- #adapt_input(message) ⇒ Object
- #adapt_output(message) ⇒ Object
-
#initialize(dispatcher, plugins) ⇒ AdapterRunner
constructor
A new instance of AdapterRunner.
- #shutdown ⇒ Object
Constructor Details
#initialize(dispatcher, plugins) ⇒ AdapterRunner
Returns a new instance of AdapterRunner.
26 27 28 29 30 31 32 33 |
# File 'lib/droonga/adapter_runner.rb', line 26 def initialize(dispatcher, plugins) @dispatcher = dispatcher default_plugins = ["error"] plugins += (default_plugins - plugins) logger.debug("activating plugins: #{plugins.join(", ")}") @adapter_classes = Adapter.find_sub_classes(plugins) logger.debug("activated:\n#{@adapter_classes.join("\n")}") end |
Instance Method Details
#adapt_input(message) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/droonga/adapter_runner.rb', line 38 def adapt_input() logger.trace("adapt_input: start", :dataset => ["dataset"], :type => ["type"]) = ["appliedAdapters"] = [] @adapter_classes.each do |adapter_class| adapter_class_id = adapter_class.id pattern = adapter_class..pattern if pattern matcher = MessageMatcher.new(pattern) logger.trace("adapt_input: skip: #{adapter_class_id}", :pattern => pattern) next unless matcher.match?() end logger.trace("adapt_input: use: #{adapter_class_id}") = InputMessage.new() adapter = adapter_class.new adapter.adapt_input() = . ["appliedAdapters"] << adapter_class_id end logger.trace("adapt_input: done", :dataset => ["dataset"], :type => ["type"]) end |
#adapt_output(message) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/droonga/adapter_runner.rb', line 66 def adapt_output() logger.trace("adapt_output: start", :dataset => ["dataset"], :type => ["type"]) = applied_adapters = ["appliedAdapters"] @adapter_classes.reverse_each do |adapter_class| adapter_class_id = adapter_class.id if applied_adapters logger.trace("adapt_output: skip: #{adapter_class_id}: " + "input adapter wasn't applied", :applied_adapters => applied_adapters) next unless applied_adapters.include?(adapter_class.id) end pattern = adapter_class..pattern if pattern matcher = MessageMatcher.new(pattern) logger.trace("adapt_output: skip: #{adapter_class_id}", :pattern => pattern) next unless matcher.match?() end logger.trace("adapt_output: use: #{adapter_class_id}") = OutputMessage.new() adapter = adapter_class.new adapter.adapt_output() = . end logger.trace("adapt_output: done", :dataset => ["dataset"], :type => ["type"]) end |
#shutdown ⇒ Object
35 36 |
# File 'lib/droonga/adapter_runner.rb', line 35 def shutdown end |