Navigation Menu

Skip to content

Commit

Permalink
adapter: split message configuration for input and output
Browse files Browse the repository at this point in the history
Before:

    message.input_pattern  = []
    message.output_pattern = []

After:

    input_message.pattern  = []
    output_message.pattern = []

This is backward incompatible change but it is OK. Because we don't
release 1.0.0 yet.
  • Loading branch information
kou committed Feb 17, 2014
1 parent abec5e2 commit d8e362f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 25 deletions.
11 changes: 8 additions & 3 deletions lib/droonga/adapter.rb
Expand Up @@ -14,15 +14,20 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "droonga/pluggable"
require "droonga/plugin/metadata/adapter_message"
require "droonga/plugin/metadata/adapter_input_message"
require "droonga/plugin/metadata/adapter_output_message"

module Droonga
class Adapter
extend Pluggable

class << self
def message
Plugin::Metadata::AdapterMessage.new(self)
def input_message
Plugin::Metadata::AdapterInputMessage.new(self)
end

def output_message
Plugin::Metadata::AdapterOutputMessage.new(self)
end

def id
Expand Down
4 changes: 2 additions & 2 deletions lib/droonga/adapter_runner.rb
Expand Up @@ -40,7 +40,7 @@ def adapt_input(message)
adapted_message["appliedAdapters"] = []
@adapter_classes.each do |adapter_class|
adapter_class_id = adapter_class.id
pattern = adapter_class.message.input_pattern
pattern = adapter_class.input_message.pattern
if pattern
matcher = MessageMatcher.new(pattern)
$log.trace("#{log_tag}: adapt_input: skip: #{adapter_class_id}",
Expand Down Expand Up @@ -74,7 +74,7 @@ def adapt_output(message)
:applied_adapters => applied_adapters)
next unless applied_adapters.include?(adapter_class.id)
end
pattern = adapter_class.message.output_pattern
pattern = adapter_class.output_message.pattern
if pattern
matcher = MessageMatcher.new(pattern)
$log.trace("#{log_tag}: adapt_output: skip: #{adapter_class_id}",
Expand Down
Expand Up @@ -16,30 +16,22 @@
module Droonga
module Plugin
module Metadata
class AdapterMessage
class AdapterInputMessage
def initialize(adapter_class)
@adapter_class = adapter_class
end

def input_pattern
configuration[:input_pattern]
def pattern
configuration[:pattern]
end

def input_pattern=(pattern)
configuration[:input_pattern] = pattern
end

def output_pattern
configuration[:output_pattern]
end

def output_pattern=(pattern)
configuration[:output_pattern] = pattern
def pattern=(pattern)
configuration[:pattern] = pattern
end

private
def configuration
@adapter_class.options[:message] ||= {}
@adapter_class.options[:input_message] ||= {}
end
end
end
Expand Down
39 changes: 39 additions & 0 deletions lib/droonga/plugin/metadata/adapter_output_message.rb
@@ -0,0 +1,39 @@
# Copyright (C) 2014 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

module Droonga
module Plugin
module Metadata
class AdapterOutputMessage
def initialize(adapter_class)
@adapter_class = adapter_class
end

def pattern
configuration[:pattern]
end

def pattern=(pattern)
configuration[:pattern] = pattern
end

private
def configuration
@adapter_class.options[:output_message] ||= {}
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/droonga/plugins/crud.rb
Expand Up @@ -24,8 +24,8 @@ module CRUD
Plugin.registry.register("crud", self)

class Adapter < Droonga::Adapter
message.input_pattern = ["type", :equal, "add"]
message.output_pattern = ["body.success", :exist]
input_message.pattern = ["type", :equal, "add"]
output_message.pattern = ["body.success", :exist]

def adapt_output(output_message)
success = output_message.body["success"]
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/plugins/error.rb
Expand Up @@ -21,7 +21,7 @@ module Error
Plugin.registry.register("error", self)

class Adapter < Droonga::Adapter
message.output_pattern = ["body.errors", :exist]
output_message.pattern = ["body.errors", :exist]

def adapt_output(output_message)
errors = output_message.body["errors"]
Expand Down
4 changes: 2 additions & 2 deletions lib/droonga/plugins/groonga/generic_response.rb
Expand Up @@ -25,8 +25,8 @@ class Adapter < Droonga::Adapter
"table_remove",
"column_create",
]
message.input_pattern = ["type", :in, groonga_commands]
message.output_pattern = ["body.result", :exist]
input_message.pattern = ["type", :in, groonga_commands]
output_message.pattern = ["body.result", :exist]

def adapt_output(output_message)
output_message.body = output_message.body["result"]
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/plugins/groonga/select.rb
Expand Up @@ -101,7 +101,7 @@ def convert(search_response)
end

class Adapter < Droonga::Adapter
message.input_pattern = ["type", :equal, "select"]
input_message.pattern = ["type", :equal, "select"]

def adapt_input(input_message)
converter = RequestConverter.new
Expand Down

0 comments on commit d8e362f

Please sign in to comment.