[Groonga-commit] droonga/fluent-plugin-droonga at 62739d8 [master] Extract AttributeFormattable module

Back to archive index

Yoji Shidara null+****@clear*****
Thu Jan 23 11:05:42 JST 2014


Yoji Shidara	2014-01-23 11:05:42 +0900 (Thu, 23 Jan 2014)

  New Revision: 62739d8d23750685b0c7d040057cf4b3cc44988f
  https://github.com/droonga/fluent-plugin-droonga/commit/62739d8d23750685b0c7d040057cf4b3cc44988f

  Merged 1ab6677: Merge branch 'output-attributes'

  Message:
    Extract AttributeFormattable module

  Modified files:
    lib/droonga/searcher.rb

  Modified: lib/droonga/searcher.rb (+31 -25)
===================================================================
--- lib/droonga/searcher.rb    2014-01-23 10:52:31 +0900 (e522bd3)
+++ lib/droonga/searcher.rb    2014-01-23 11:05:42 +0900 (e9cca0a)
@@ -361,28 +361,41 @@ module Droonga
       end
     end
 
-    class SimpleAttributesFormatter
+    module AttributeFormattable
       def format_attribute(attribute, table)
         label = attribute[:label]
         source = attribute[:source]
         if source == "_subrecs"
           sub_record_table = table.range
           sub_attributes = format(attribute[:attributes], sub_record_table)
-          {
-            "name" => label,
-            "attributes" => sub_attributes,
-          }
+
+          format_attribute_subrecs(label, sub_attributes)
         else
           expression = attribute[:expression]
           if expression
             # TODO implement
           else
             column = table.column(source)
-            vector = column.respond_to?(:vector?) ? column.vector? : false
-            {"name" => label, "type" => column.range.name, "vector" => vector}
+            format_attribute_column(label, column)
           end
         end
       end
+    end
+
+    class SimpleAttributesFormatter
+      include AttributeFormattable
+
+      def format_attribute_subrecs(label, sub_attributes)
+        {
+          "name" => label,
+          "attributes" => sub_attributes,
+        }
+      end
+
+      def format_attribute_column(label, column)
+        vector = column.respond_to?(:vector?) ? column.vector? : false
+        {"name" => label, "type" => column.range.name, "vector" => vector}
+      end
 
       def format(attributes, table)
         attributes.collect do |attribute|
@@ -392,24 +405,17 @@ module Droonga
     end
 
     class ComplexAttributesFormatter
-      def format_attribute(attribute, table)
-        source = attribute[:source]
-        if source == "_subrecs"
-          sub_record_table = table.range
-          sub_attributes = format(attribute[:attributes], sub_record_table)
-          {
-            "attributes" => sub_attributes
-          }
-        else
-          expression = attribute[:expression]
-          if expression
-            # TODO implement
-          else
-            column = table.column(source)
-            vector = column.respond_to?(:vector?) ? column.vector? : false
-            {"type" => column.range.name, "vector" => vector}
-          end
-        end
+      include AttributeFormattable
+
+      def format_attribute_subrecs(label, sub_attributes)
+        {
+          "attributes" => sub_attributes
+        }
+      end
+
+      def format_attribute_column(label, column)
+        vector = column.respond_to?(:vector?) ? column.vector? : false
+        {"type" => column.range.name, "vector" => vector}
       end
 
       def format(attributes, table)
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index