fluent-plugin-droonga 0.9.0 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/Gemfile +8 -1
  4. data/fluent-plugin-droonga.gemspec +2 -2
  5. data/lib/droonga/adapter.rb +39 -0
  6. data/lib/droonga/adapter_runner.rb +99 -0
  7. data/lib/droonga/catalog/base.rb +11 -11
  8. data/lib/droonga/catalog/dataset.rb +54 -0
  9. data/lib/droonga/catalog/version1.rb +1 -1
  10. data/lib/droonga/collector.rb +5 -7
  11. data/lib/droonga/collector_plugin.rb +7 -7
  12. data/lib/droonga/command.rb +36 -0
  13. data/lib/droonga/{plugin/input_adapter/crud.rb → command_repository.rb} +14 -8
  14. data/lib/droonga/dispatcher.rb +86 -54
  15. data/lib/droonga/distributed_command_planner.rb +183 -0
  16. data/lib/droonga/distributor.rb +43 -17
  17. data/lib/droonga/handler.rb +13 -72
  18. data/lib/droonga/handler_message.rb +5 -5
  19. data/lib/droonga/handler_messenger.rb +4 -1
  20. data/lib/droonga/handler_plugin.rb +2 -2
  21. data/lib/droonga/handler_runner.rb +104 -0
  22. data/lib/droonga/input_message.rb +4 -4
  23. data/lib/droonga/legacy_pluggable.rb +66 -0
  24. data/lib/droonga/{input_adapter.rb → legacy_plugin.rb} +27 -22
  25. data/lib/droonga/{plugin_repository.rb → legacy_plugin_repository.rb} +2 -4
  26. data/lib/droonga/message_matcher.rb +101 -0
  27. data/lib/droonga/{input_adapter_plugin.rb → planner.rb} +14 -10
  28. data/lib/droonga/planner_plugin.rb +54 -0
  29. data/lib/droonga/pluggable.rb +9 -45
  30. data/lib/droonga/plugin.rb +9 -33
  31. data/lib/droonga/plugin/collector/basic.rb +2 -0
  32. data/lib/droonga/plugin/collector/search.rb +31 -37
  33. data/lib/droonga/plugin/{handler/groonga/table_remove.rb → metadata/adapter_message.rb} +23 -18
  34. data/lib/droonga/plugin/{handler/search.rb → metadata/handler_action.rb} +19 -15
  35. data/lib/droonga/plugin/metadata/input_message.rb +39 -0
  36. data/lib/droonga/plugin/planner/crud.rb +49 -0
  37. data/lib/droonga/plugin/{distributor → planner}/distributed_search_planner.rb +62 -70
  38. data/lib/droonga/plugin/{distributor → planner}/groonga.rb +11 -32
  39. data/lib/droonga/plugin/{distributor → planner}/search.rb +5 -5
  40. data/lib/droonga/plugin/{distributor → planner}/watch.rb +15 -6
  41. data/lib/droonga/plugin_loader.rb +10 -0
  42. data/lib/droonga/plugin_registerable.rb +34 -10
  43. data/lib/droonga/plugin_registry.rb +58 -0
  44. data/lib/droonga/plugins/crud.rb +124 -0
  45. data/lib/droonga/plugins/error.rb +50 -0
  46. data/lib/droonga/{output_adapter_plugin.rb → plugins/groonga.rb} +9 -13
  47. data/lib/droonga/plugins/groonga/column_create.rb +123 -0
  48. data/lib/droonga/plugins/groonga/generic_command.rb +65 -0
  49. data/lib/droonga/{plugin/output_adapter/groonga.rb → plugins/groonga/generic_response.rb} +16 -15
  50. data/lib/droonga/plugins/groonga/select.rb +124 -0
  51. data/lib/droonga/plugins/groonga/table_create.rb +106 -0
  52. data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
  53. data/lib/droonga/plugins/search.rb +40 -0
  54. data/lib/droonga/plugins/watch.rb +156 -0
  55. data/lib/droonga/processor.rb +8 -10
  56. data/lib/droonga/searcher.rb +14 -4
  57. data/lib/droonga/searcher/mecab_filter.rb +67 -0
  58. data/lib/droonga/session.rb +5 -5
  59. data/lib/droonga/test.rb +1 -1
  60. data/lib/droonga/test/stub_handler_message.rb +1 -1
  61. data/lib/droonga/test/{stub_distributor.rb → stub_planner.rb} +1 -1
  62. data/lib/droonga/worker.rb +7 -8
  63. data/lib/fluent/plugin/out_droonga.rb +0 -1
  64. data/sample/cluster/catalog.json +2 -4
  65. data/sample/mecab_filter/data.grn +7 -0
  66. data/sample/mecab_filter/ddl.grn +7 -0
  67. data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
  68. data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
  69. data/test/command/config/default/catalog.json +2 -5
  70. data/test/command/suite/search/error/no-query.expected +13 -0
  71. data/test/command/suite/search/error/no-query.test +7 -0
  72. data/test/command/suite/search/error/unknown-source.expected +26 -0
  73. data/test/command/suite/watch/subscribe.expected +3 -3
  74. data/test/command/suite/watch/unsubscribe.expected +3 -3
  75. data/test/unit/catalog/test_dataset.rb +385 -0
  76. data/test/unit/catalog/test_version1.rb +111 -45
  77. data/test/unit/fixtures/catalog/version1.json +0 -3
  78. data/test/unit/helper.rb +2 -1
  79. data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
  80. data/test/unit/plugin/collector/test_basic.rb +233 -376
  81. data/test/unit/plugin/collector/test_search.rb +8 -17
  82. data/test/unit/plugin/planner/search_planner/test_basic.rb +120 -0
  83. data/test/unit/plugin/planner/search_planner/test_group_by.rb +573 -0
  84. data/test/unit/plugin/planner/search_planner/test_output.rb +388 -0
  85. data/test/unit/plugin/planner/search_planner/test_sort_by.rb +938 -0
  86. data/test/unit/plugin/{distributor → planner}/test_search.rb +20 -75
  87. data/test/unit/{plugin/handler → plugins/crud}/test_add.rb +11 -11
  88. data/test/unit/plugins/groonga/select/test_adapter_input.rb +213 -0
  89. data/test/unit/{plugin/output_adapter/groonga/test_select.rb → plugins/groonga/select/test_adapter_output.rb} +12 -13
  90. data/test/unit/{plugin/handler → plugins}/groonga/test_column_create.rb +20 -5
  91. data/test/unit/{plugin/handler → plugins}/groonga/test_table_create.rb +5 -0
  92. data/test/unit/{plugin/handler → plugins}/groonga/test_table_remove.rb +8 -1
  93. data/test/unit/{plugin/handler → plugins}/test_groonga.rb +5 -5
  94. data/test/unit/{plugin/handler → plugins}/test_search.rb +21 -5
  95. data/test/unit/{plugin/handler → plugins}/test_watch.rb +29 -10
  96. data/{lib/droonga/command_mapper.rb → test/unit/test_command_repository.rb} +16 -22
  97. data/test/unit/{test_plugin.rb → test_legacy_plugin.rb} +3 -3
  98. data/test/unit/{test_plugin_repository.rb → test_legacy_plugin_repository.rb} +3 -3
  99. data/test/unit/test_message_matcher.rb +137 -0
  100. metadata +86 -66
  101. data/bin/grn2jsons +0 -82
  102. data/lib/droonga/distribution_planner.rb +0 -76
  103. data/lib/droonga/distributor_plugin.rb +0 -95
  104. data/lib/droonga/output_adapter.rb +0 -53
  105. data/lib/droonga/plugin/collector/groonga.rb +0 -83
  106. data/lib/droonga/plugin/distributor/crud.rb +0 -84
  107. data/lib/droonga/plugin/handler/add.rb +0 -109
  108. data/lib/droonga/plugin/handler/forward.rb +0 -75
  109. data/lib/droonga/plugin/handler/groonga.rb +0 -99
  110. data/lib/droonga/plugin/handler/groonga/column_create.rb +0 -106
  111. data/lib/droonga/plugin/handler/groonga/table_create.rb +0 -91
  112. data/lib/droonga/plugin/handler/watch.rb +0 -108
  113. data/lib/droonga/plugin/input_adapter/groonga.rb +0 -49
  114. data/lib/droonga/plugin/input_adapter/groonga/select.rb +0 -63
  115. data/lib/droonga/plugin/output_adapter/crud.rb +0 -51
  116. data/lib/droonga/plugin/output_adapter/groonga/select.rb +0 -54
  117. data/lib/groonga_command_converter.rb +0 -143
  118. data/sample/fluentd.conf +0 -8
  119. data/test/unit/plugin/distributor/test_search_planner.rb +0 -1102
  120. data/test/unit/plugin/input_adapter/groonga/test_select.rb +0 -248
  121. data/test/unit/test_command_mapper.rb +0 -44
  122. data/test/unit/test_groonga_command_converter.rb +0 -242
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80594c4e021918c28b58451b90293961f7b65174
4
- data.tar.gz: ff89eb342312841a7d9eaa8831a7d190bec34c35
3
+ metadata.gz: 24503ddfa77a2b4c19b83b771069a3c91f738ef2
4
+ data.tar.gz: 50f89c1a0fed25c58d8d16b5e16c41258cbd4e3a
5
5
  SHA512:
6
- metadata.gz: 39351f8baffeae2e33ac2b3d1ad6f06c39fe08a626ee8f260c62501e03b5acb05a67f2e0667833250f200679664d518da774b57c2356c30f260cd0afb83f8940
7
- data.tar.gz: c26dd8db11b63e7f6130826f6eb4ce97b05dae064e39b9502b3cc7cbf0f54a912c5fc3885bab2855ace0a21cba9af851e64e9a4d40c136310790c848d9e0aadd
6
+ metadata.gz: d6b1075946a566e9a92703c682a160ece90bfe8e46e7ec2f722617048d25e54b6453aa25ffc91582e12267bd773904d88605b16a20648dc05536f9943bd00e44
7
+ data.tar.gz: 4140cc01d656daed66444a853ea585c4aec6fc55b10361e29eac617f924b421d2a3aa2fe17519a5c585ffd8d044b55d01e32e76924bb2ed2ecd441af4ae82ed9
data/.travis.yml CHANGED
@@ -3,5 +3,8 @@ notifications:
3
3
  - groonga-commit@lists.sourceforge.jp
4
4
  rvm:
5
5
  - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - ruby-head
6
9
  before_install:
7
10
  - curl https://raw.github.com/groonga/groonga/master/data/travis/setup.sh | sh
data/Gemfile CHANGED
@@ -27,7 +27,7 @@ if File.exist?(local_rroonga_path)
27
27
  gem "groonga-command", :path => local_groonga_command_path
28
28
  gem "groonga-command-parser", :path => local_groonga_command_parser_path
29
29
  elsif ENV["TRAVIS"] == "true"
30
- require_unreleased_gems = false
30
+ require_unreleased_gems = true
31
31
  if require_unreleased_gems
32
32
  gem "rroonga", :git => "git://github.com/ranguba/rroonga.git"
33
33
  gem "groonga-command",
@@ -57,3 +57,10 @@ if File.exist?(drnbench_dir)
57
57
  else
58
58
  gem "drnbench", :github => "droonga/drnbench"
59
59
  end
60
+
61
+ grn2drn_dir = File.join(parent_dir, "grn2drn")
62
+ if File.exist?(grn2drn_dir)
63
+ gem "grn2drn", :path => grn2drn_dir
64
+ else
65
+ gem "grn2drn", :github => "droonga/grn2drn"
66
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2013 Droonga Project
3
+ # Copyright (C) 2013-2014 Droonga Project
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,7 @@
17
17
 
18
18
  Gem::Specification.new do |gem|
19
19
  gem.name = "fluent-plugin-droonga"
20
- gem.version = "0.9.0"
20
+ gem.version = "0.9.9"
21
21
  gem.authors = ["Droonga Project"]
22
22
  gem.email = ["droonga@groonga.org"]
23
23
  gem.description = "Droonga(distributed Groonga) plugin for Fluent event collector"
@@ -0,0 +1,39 @@
1
+ # Copyright (C) 2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "droonga/pluggable"
17
+ require "droonga/plugin/metadata/adapter_message"
18
+
19
+ module Droonga
20
+ class Adapter
21
+ extend Pluggable
22
+
23
+ class << self
24
+ def message
25
+ Plugin::Metadata::AdapterMessage.new(self)
26
+ end
27
+
28
+ def id
29
+ options[:id] || name || object_id.to_s
30
+ end
31
+ end
32
+
33
+ def adapt_input(input_message)
34
+ end
35
+
36
+ def adapt_output(output_message)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,99 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "droonga/message_matcher"
17
+ require "droonga/input_message"
18
+ require "droonga/output_message"
19
+ require "droonga/adapter"
20
+
21
+ module Droonga
22
+ class AdapterRunner
23
+ def initialize(dispatcher, plugins)
24
+ @dispatcher = dispatcher
25
+ default_plugins = ["error"]
26
+ plugins += (default_plugins - plugins)
27
+ @adapter_classes = Adapter.find_sub_classes(plugins)
28
+ end
29
+
30
+ def shutdown
31
+ end
32
+
33
+ def adapt_input(message)
34
+ $log.trace("#{log_tag}: adapt_input: start",
35
+ :dataset => message["dataset"],
36
+ :type => message["type"])
37
+ adapted_message = message
38
+ adapted_message["appliedAdapters"] = []
39
+ @adapter_classes.each do |adapter_class|
40
+ adapter_class_id = adapter_class.id
41
+ pattern = adapter_class.message.input_pattern
42
+ if pattern
43
+ matcher = MessageMatcher.new(pattern)
44
+ $log.trace("#{log_tag}: adapt_input: skip: #{adapter_class_id}",
45
+ :pattern => pattern)
46
+ next unless matcher.match?(adapted_message)
47
+ end
48
+ $log.trace("#{log_tag}: adapt_input: use: #{adapter_class_id}")
49
+ input_message = InputMessage.new(adapted_message)
50
+ adapter = adapter_class.new
51
+ adapter.adapt_input(input_message)
52
+ adapted_message = input_message.adapted_message
53
+ adapted_message["appliedAdapters"] << adapter_class_id
54
+ end
55
+ $log.trace("#{log_tag}: adapt_input: done",
56
+ :dataset => adapted_message["dataset"],
57
+ :type => adapted_message["type"])
58
+ adapted_message
59
+ end
60
+
61
+ def adapt_output(message)
62
+ $log.trace("#{log_tag}: adapt_output: start",
63
+ :dataset => message["dataset"],
64
+ :type => message["type"])
65
+ adapted_message = message
66
+ applied_adapters = adapted_message["appliedAdapters"]
67
+ @adapter_classes.reverse_each do |adapter_class|
68
+ adapter_class_id = adapter_class.id
69
+ if applied_adapters
70
+ $log.trace("#{log_tag}: adapt_output: skip: #{adapter_class_id}: " +
71
+ "input adapter wasn't applied",
72
+ :applied_adapters => applied_adapters)
73
+ next unless applied_adapters.include?(adapter_class.id)
74
+ end
75
+ pattern = adapter_class.message.output_pattern
76
+ if pattern
77
+ matcher = MessageMatcher.new(pattern)
78
+ $log.trace("#{log_tag}: adapt_output: skip: #{adapter_class_id}",
79
+ :pattern => pattern)
80
+ next unless matcher.match?(adapted_message)
81
+ end
82
+ $log.trace("#{log_tag}: adapt_output: use: #{adapter_class_id}")
83
+ output_message = OutputMessage.new(adapted_message)
84
+ adapter = adapter_class.new
85
+ adapter.adapt_output(output_message)
86
+ adapted_message = output_message.adapted_message
87
+ end
88
+ $log.trace("#{log_tag}: adapt_output: done",
89
+ :dataset => adapted_message["dataset"],
90
+ :type => adapted_message["type"])
91
+ adapted_message
92
+ end
93
+
94
+ private
95
+ def log_tag
96
+ "adapter-runner"
97
+ end
98
+ end
99
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 Droonga Project
1
+ # Copyright (C) 2013-2014 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -20,12 +20,6 @@ require "droonga/message_processing_error"
20
20
  module Droonga
21
21
  module Catalog
22
22
  class Base
23
- class UnknownDataset < NotFound
24
- def initialize(dataset)
25
- super("The dataset #{dataset.inspect} does not exist.")
26
- end
27
- end
28
-
29
23
  attr_reader :base_path
30
24
  def initialize(data, base_path)
31
25
  @data = data
@@ -68,7 +62,7 @@ module Droonga
68
62
  options = {
69
63
  :database => path,
70
64
  :n_workers => workers,
71
- :handlers => plugins
65
+ :plugins => plugins
72
66
  }
73
67
  results[partition] = options
74
68
  end
@@ -114,10 +108,16 @@ module Droonga
114
108
  return continuum[max][1]
115
109
  end
116
110
 
111
+ def datasets
112
+ @data["datasets"] || {}
113
+ end
114
+
115
+ def have_dataset?(name)
116
+ datasets.key?(name)
117
+ end
118
+
117
119
  def dataset(name)
118
- dataset = @data["datasets"][name]
119
- raise UnknownDataset.new(name) unless dataset
120
- dataset
120
+ datasets[name]
121
121
  end
122
122
 
123
123
  def select_range_and_replicas(partition, args, routes)
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "digest/sha1"
17
+
18
+ module Droonga
19
+ module Catalog
20
+ class Dataset
21
+ def initialize(data)
22
+ @data = data
23
+ end
24
+
25
+ def continuum
26
+ @continuum ||= compute_continuum
27
+ end
28
+
29
+ private
30
+ def compute_continuum
31
+ number_of_partitions = @data["number_of_partitions"]
32
+ return [] if number_of_partitions < 2
33
+ total_weight = compute_total_weight
34
+ continuum = []
35
+ @data["ring"].each do |key, value|
36
+ points = number_of_partitions * 160 * value["weight"] / total_weight
37
+ points.times do |point|
38
+ hash = Digest::SHA1.hexdigest("#{key}:#{point}")
39
+ continuum << [hash[0..7].to_i(16), key]
40
+ end
41
+ end
42
+ continuum.sort do |a, b|
43
+ a[0] - b[0]
44
+ end
45
+ end
46
+
47
+ def compute_total_weight
48
+ @data["ring"].reduce(0) do |result, zone|
49
+ result + zone[1]["weight"]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 Droonga Project
1
+ # Copyright (C) 2013-2014 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013 Droonga Project
1
+ # Copyright (C) 2013-2014 Droonga Project
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
6
4
  # modify it under the terms of the GNU Lesser General Public
@@ -15,15 +13,15 @@
15
13
  # License along with this library; if not, write to the Free Software
16
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
15
 
18
- require "droonga/pluggable"
16
+ require "droonga/legacy_pluggable"
19
17
  require "droonga/collector_plugin"
20
18
 
21
19
  module Droonga
22
20
  class Collector
23
- include Pluggable
21
+ include LegacyPluggable
24
22
 
25
- def initialize
26
- load_plugins(["basic", "search", "groonga"]) # TODO: make customizable
23
+ def initialize(plugins)
24
+ load_plugins(plugins)
27
25
  end
28
26
 
29
27
  private
@@ -15,13 +15,13 @@
15
15
  # License along with this library; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
 
18
- require "droonga/plugin"
18
+ require "droonga/legacy_plugin"
19
19
 
20
20
  module Droonga
21
- class CollectorPlugin < Plugin
21
+ class CollectorPlugin < LegacyPlugin
22
22
  extend PluginRegisterable
23
23
 
24
- attr_reader :task, :input_name, :component, :output_values, :body, :output_names
24
+ attr_reader :task, :input_name, :step, :output_values, :body, :output_names
25
25
  def initialize
26
26
  super()
27
27
  end
@@ -30,11 +30,11 @@ module Droonga
30
30
  return false unless message.is_a? Hash
31
31
  @task = message["task"]
32
32
  return false unless @task.is_a? Hash
33
- @component = @task["component"]
34
- return false unless @component.is_a? Hash
33
+ @step = @task["step"]
34
+ return false unless @step.is_a? Hash
35
35
  @output_values = @task["values"]
36
- @body = @component["body"]
37
- @output_names = @component["outputs"]
36
+ @body = @step["body"]
37
+ @output_names = @step["outputs"]
38
38
  @id = message["id"]
39
39
  @value = message["value"]
40
40
  @input_name = message["name"]
@@ -0,0 +1,36 @@
1
+ # Copyright (C) 2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "droonga/message_matcher"
17
+
18
+ module Droonga
19
+ class Command
20
+ attr_reader :method_name
21
+ # @option options [Array] :pattern The pattern to be matched
22
+ # against message. If the pattern is matched to a message,
23
+ # the command will be applied.
24
+ #
25
+ # @see MessageMatcher
26
+ def initialize(method_name, options)
27
+ @method_name = method_name
28
+ @options = options
29
+ @matcher = MessageMatcher.new(@options[:pattern])
30
+ end
31
+
32
+ def match?(message)
33
+ @matcher.match?(message)
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Droonga Project
1
+ # Copyright (C) 2013-2014 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -13,15 +13,21 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
- require "droonga/input_adapter_plugin"
17
-
18
16
  module Droonga
19
- class CRUDInputAdapter < Droonga::InputAdapterPlugin
20
- repository.register("crud", self)
17
+ class CommandRepository
18
+ attr_reader :commands
19
+ def initialize
20
+ @commands = []
21
+ end
22
+
23
+ def register(command)
24
+ @commands << command
25
+ end
21
26
 
22
- command :add
23
- def add(input_message)
24
- input_message.add_route("crud_generic_response")
27
+ def find(message)
28
+ @commands.find do |command|
29
+ command.match?(message)
30
+ end
25
31
  end
26
32
  end
27
33
  end