[Groonga-commit] droonga/fluent-plugin-droonga at 256208f [master] schema: Add Droonga::Catalog::Schema::{Table, Column}

Back to archive index

Yoji Shidara null+****@clear*****
Tue Feb 18 12:57:04 JST 2014


Yoji Shidara	2014-02-18 12:57:04 +0900 (Tue, 18 Feb 2014)

  New Revision: 256208f2c36bc860164d52598a8798678f4c980a
  https://github.com/droonga/fluent-plugin-droonga/commit/256208f2c36bc860164d52598a8798678f4c980a

  Message:
    schema: Add Droonga::Catalog::Schema::{Table,Column}

  Copied files:
    test/unit/catalog/test_schema.rb
      (from lib/droonga/catalog/schema.rb)
  Modified files:
    lib/droonga/catalog/schema.rb

  Modified: lib/droonga/catalog/schema.rb (+46 -2)
===================================================================
--- lib/droonga/catalog/schema.rb    2014-02-18 12:05:48 +0900 (5a059b5)
+++ lib/droonga/catalog/schema.rb    2014-02-18 12:57:04 +0900 (4f93298)
@@ -16,11 +16,55 @@
 module Droonga
   module Catalog
     class Schema
+      class Columns
+        attr_reader :name
+        def initialize(name, data)
+          @name = name
+          @data = data
+        end
+
+        def ==(other)
+          self.class == other.class and
+            name == other.name
+          # TODO should consider @data
+        end
+      end
+
+      class Table
+        attr_reader :name, :columns
+        def initialize(name, data)
+          @name = name
+          @data = data
+
+          @columns = columns_data.map do |column_name, column_data|
+            Column.new(column_name, column_data)
+          end
+        end
+
+        def ==(other)
+          self.class == other.class and
+            name == other.name and
+            columns == other.columns
+        end
+
+        private
+        def columns_data
+          @data["columns"] || []
+        end
+      end
+
+      attr_reader :tables
       def initialize(data)
-        @data = data
+        @data = data || []
+        @tables =****@data***** do |table_name, table_data|
+          Table.new(table_name, table_data)
+        end
       end
 
-      # TODO provide useful methods
+      def ==(other)
+        self.class == other.class and
+          tables == other.tables
+      end
     end
   end
 end

  Copied: test/unit/catalog/test_schema.rb (+25 -7) 55%
===================================================================
--- lib/droonga/catalog/schema.rb    2014-02-18 12:05:48 +0900 (5a059b5)
+++ test/unit/catalog/test_schema.rb    2014-02-18 12:57:04 +0900 (a4fce62)
@@ -13,14 +13,32 @@
 # 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 Catalog
-    class Schema
-      def initialize(data)
-        @data = data
-      end
+require "droonga/catalog/schema"
 
-      # TODO provide useful methods
+class CatalogSchemaTest < Test::Unit::TestCase
+  private
+  def create_schema(data)
+    Droonga::Catalog::Schema.new(data)
+  end
+
+  class SchemaTest < self
+    def test_schema_not_specified
+      assert_equal([],
+                   create_schema(nil).tables)
+    end
+
+    def test_no_table
+      assert_equal([],
+                   create_schema({}).tables)
+    end
+
+    def test_tables
+      assert_equal(
+        [Droonga::Catalog::Schema::Table.new('table1', {})],
+        create_schema(
+          "table1" => {
+        }).tables
+      )
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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