Sha256: 13c0b32d065ccb9c6fe74c0bbd1a609b548c3ac522522b81507c327bcf236949

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

# 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
# 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 "pathname"
require "socket"
require "stringio"
require "uri"

require "groonga/client/test/groonga-server-runner"

require "groonga_client_model/migrator"

module GroongaClientModel
  module Test
    class GroongaServerRunner < Groonga::Client::Test::GroongaServerRunner
      def initialize
        super
        @client = Client.new
      end

      def run
        super
        return if using_running_server?

        if defined?(Rails)
          base_dir = Rails.root
        else
          base_dir = Pathname.pwd
        end

        schema_path = base_dir + SchemaLoader.default_path
        migrate_path = base_dir + Migrator.default_search_path
        if schema_path.exist?
          schema_path.open do |schema_file|
            schema_loader = SchemaLoader.new(schema_file)
            schema_loader.load
          end
        elsif migrate_path.exist?
          output = StringIO.new
          migrator = Migrator.new(migrate_path)
          migrator.output = output
          migrator.migrate
        end
      end

      def url
        @url ||= URI(@client.url)
      end

      private
      def open_client(&block)
        @client.open(&block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
groonga-client-model-1.0.2 lib/groonga_client_model/test/groonga_server_runner.rb