[Groonga-commit] ranguba/groonga-client-model at f1121e0 [master] Share common code

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Dec 20 16:44:37 JST 2016


Kouhei Sutou	2016-12-20 16:44:37 +0900 (Tue, 20 Dec 2016)

  New Revision: f1121e09bc09c0e21c325d35d575d05a14409f48
  https://github.com/ranguba/groonga-client-model/commit/f1121e09bc09c0e21c325d35d575d05a14409f48

  Message:
    Share common code

  Copied files:
    lib/groonga_client_model/schema_loader.rb
      (from lib/groonga_client_model/railties/groonga.rake)
    lib/groonga_client_model/test/fixture.rb
      (from lib/groonga_client_model/spec_helper.rb)
  Modified files:
    lib/groonga-client-model.rb
    lib/groonga_client_model/railties/groonga.rake
    lib/groonga_client_model/spec_helper.rb
    lib/groonga_client_model/test_helper.rb

  Modified: lib/groonga-client-model.rb (+1 -0)
===================================================================
--- lib/groonga-client-model.rb    2016-12-20 16:34:41 +0900 (1c588af)
+++ lib/groonga-client-model.rb    2016-12-20 16:44:37 +0900 (b70ab62)
@@ -28,6 +28,7 @@ require "groonga_client_model/modelizable"
 require "groonga_client_model/modelize"
 require "groonga_client_model/record"
 require "groonga_client_model/schema"
+require "groonga_client_model/schema_loader"
 
 module GroongaClientModel
   mattr_accessor :logger, instance_writer: false

  Modified: lib/groonga_client_model/railties/groonga.rake (+2 -16)
===================================================================
--- lib/groonga_client_model/railties/groonga.rake    2016-12-20 16:34:41 +0900 (dfe8c0c)
+++ lib/groonga_client_model/railties/groonga.rake    2016-12-20 16:44:37 +0900 (21d3c91)
@@ -28,22 +28,8 @@ namespace :groonga do
   namespace :schema do
     desc "Loads config/schema.grn info Groonga"
     task load: ["config:load"] do
-      require "groonga/command/parser"
-
-      schema_path = Rails.root + "db/schema.grn"
-      GroongaClientModel::Client.open do |client|
-        parser = Groonga::Command::Parser.new
-        parser.on_command do |command|
-          client.execute(command)
-        end
-
-        schema_path.open do |schema_file|
-          schema_file.each_line do |line|
-            parser << line
-          end
-        end
-        parser.finish
-      end
+      schema_loader = GroongaClientModel::SchemaLoader.new(Rails.root)
+      schema_loader.load
     end
   end
 end

  Copied: lib/groonga_client_model/schema_loader.rb (+10 -16) 69%
===================================================================
--- lib/groonga_client_model/railties/groonga.rake    2016-12-20 16:34:41 +0900 (dfe8c0c)
+++ lib/groonga_client_model/schema_loader.rb    2016-12-20 16:44:37 +0900 (a82d322)
@@ -1,5 +1,3 @@
-# -*- ruby -*-
-#
 # Copyright (C) 2016  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
@@ -16,27 +14,23 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-namespace :groonga do
-  namespace :config do
-    desc "Load config/groonga.rb"
-    task load: [:environment] do
-      config = Rails.application.config_for(:groonga)
-      GroongaClientModel::Client.url = config["url"]
+require "groonga/command/parser"
+
+module GroongaClientModel
+  class SchemaLoader
+    def initialize(base_dir)
+      @base_dir = base_dir
     end
-  end
 
-  namespace :schema do
-    desc "Loads config/schema.grn info Groonga"
-    task load: ["config:load"] do
-      require "groonga/command/parser"
+    def load
+      schema_path = @base_dir + "db" + "schema.grn"
+      return unless schema_path.exist?
 
-      schema_path = Rails.root + "db/schema.grn"
-      GroongaClientModel::Client.open do |client|
+      Client.open do |client|
         parser = Groonga::Command::Parser.new
         parser.on_command do |command|
           client.execute(command)
         end
-
         schema_path.open do |schema_file|
           schema_file.each_line do |line|
             parser << line

  Modified: lib/groonga_client_model/spec_helper.rb (+6 -0)
===================================================================
--- lib/groonga_client_model/spec_helper.rb    2016-12-20 16:34:41 +0900 (445636c)
+++ lib/groonga_client_model/spec_helper.rb    2016-12-20 16:44:37 +0900 (26e6e11)
@@ -15,6 +15,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 require "groonga/client/spec-helper"
+require "groonga_client_model/test/fixture"
 
 module GroongaClientModel
   module SpecHelper
@@ -22,6 +23,11 @@ module GroongaClientModel
 
     included do
       include Groonga::Client::SpecHelper
+      include Test::Fixture
+
+      before(:each) do
+        setup_groonga_schema
+      end
     end
   end
 end

  Copied: lib/groonga_client_model/test/fixture.rb (+12 -6) 71%
===================================================================
--- lib/groonga_client_model/spec_helper.rb    2016-12-20 16:34:41 +0900 (445636c)
+++ lib/groonga_client_model/test/fixture.rb    2016-12-20 16:44:37 +0900 (b187eb8)
@@ -14,14 +14,20 @@
 # 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 "groonga/client/spec-helper"
-
 module GroongaClientModel
-  module SpecHelper
-    extend ActiveSupport::Concern
+  module Test
+    module Fixture
+      def setup_groonga_schema
+        return if @groonga_server_runner.using_running_server?
 
-    included do
-      include Groonga::Client::SpecHelper
+        if defined?(Rails)
+          base_dir = Rails.root
+        else
+          base_dir = Pathname.pwd
+        end
+        schema_loader = SchemaLoader.new(base_dir)
+        schema_loader.load
+      end
     end
   end
 end

  Modified: lib/groonga_client_model/test_helper.rb (+3 -22)
===================================================================
--- lib/groonga_client_model/test_helper.rb    2016-12-20 16:34:41 +0900 (8799406)
+++ lib/groonga_client_model/test_helper.rb    2016-12-20 16:44:37 +0900 (231d8ad)
@@ -15,6 +15,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 require "groonga/client/test-helper"
+require "groonga_client_model/test/fixture"
 
 module GroongaClientModel
   module TestHelper
@@ -22,30 +23,10 @@ module GroongaClientModel
 
     included do
       include Groonga::Client::TestHelper
+      include Test::Fixture
 
       setup do
-        return if @groonga_server_runner.using_running_server?
-
-        if defined?(Rails)
-          base_dir = Rails.root
-        else
-          base_dir = Pathname.pwd
-        end
-        schema_grn = base_dir + "db" + "schema.grn"
-        return unless schema_grn.exist?
-
-        Client.open do |client|
-          parser = Groonga::Command::Parser.new
-          parser.on_command do |command|
-            client.execute(command)
-          end
-          schema_grn.open do |schema|
-            schema.each_line do |line|
-              parser << line
-            end
-          end
-          parser.finish
-        end
+        setup_groonga_schema
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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