[Groonga-commit] ranguba/rroonga-iruby at e4c7479 [master] Support Record

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 10 15:19:39 JST 2017


Kouhei Sutou	2017-02-10 15:19:39 +0900 (Fri, 10 Feb 2017)

  New Revision: e4c747917172b041611d3207aa0d11ec75d66aaa
  https://github.com/ranguba/rroonga-iruby/commit/e4c747917172b041611d3207aa0d11ec75d66aaa

  Message:
    Support Record

  Added files:
    lib/rroonga-iruby/record.rb
  Modified files:
    lib/rroonga-iruby.rb

  Modified: lib/rroonga-iruby.rb (+6 -1)
===================================================================
--- lib/rroonga-iruby.rb    2016-05-09 00:43:57 +0900 (82c8466)
+++ lib/rroonga-iruby.rb    2017-02-10 15:19:39 +0900 (2ad5704)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2016-2017  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -18,9 +18,14 @@ require "groonga"
 
 require "rroonga-iruby/version"
 
+require "rroonga-iruby/record"
 require "rroonga-iruby/table"
 
 module Groonga
+  class Record
+    include RroongaIRuby::Record
+  end
+
   class Table
     include RroongaIRuby::Table
   end

  Added: lib/rroonga-iruby/record.rb (+86 -0) 100644
===================================================================
--- /dev/null
+++ lib/rroonga-iruby/record.rb    2017-02-10 15:19:39 +0900 (d3b55c7)
@@ -0,0 +1,86 @@
+# Copyright (C) 2017  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "erector"
+
+module RroongaIRuby
+  module Record
+    class TableWidget < Erector::Widget
+      def initialize(record)
+        columns = record.columns
+        n_columns = 1  # _id
+        n_columns += 1 if record.support_key?
+        n_columns += columns.size
+        super(:table => record.table,
+              :record => record,
+              :columns => columns,
+              :n_columns => n_columns,
+              :size => 1)
+      end
+
+      def content
+        table do
+          thead do
+            tr do
+              th(:colspan => @n_columns) do
+                text "#{@table.name}(#{@table.class.name})"
+              end
+            end
+            tr do
+              th do
+                text "_id"
+              end
+              if****@recor*****_key?
+                th do
+                  text "_key"
+                end
+              end
+              @columns.each do |column|
+                th do
+                  text "#{column.local_name}(#{column.range.name})"
+                end
+              end
+            end
+          end
+
+          tbody do
+            tr do
+              td do
+                text****@recor*****
+              end
+              if****@recor*****_key?
+                td do
+                  text****@recor*****
+                end
+              end
+              @columns.each do |column|
+                td do
+                  value = @record[column.local_name]
+                  value = value.record_id if value.is_a?(Groonga::Record)
+                  text value
+                end
+              end
+            end
+          end
+        end
+      end
+    end
+
+    def to_html
+      TableWidget.new(self).to_html
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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