[Groonga-commit] ranguba/groonga-client-rails at 8d3f8b1 [master] Support the default Groonga client options by config/groonga_client.yml

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Mar 21 22:39:30 JST 2016


Kouhei Sutou	2016-03-21 22:39:30 +0900 (Mon, 21 Mar 2016)

  New Revision: 8d3f8b195f5cc2626d51c6493cf85730e00f70e8
  https://github.com/ranguba/groonga-client-rails/commit/8d3f8b195f5cc2626d51c6493cf85730e00f70e8

  Message:
    Support the default Groonga client options by config/groonga_client.yml

  Added files:
    lib/groonga-client-rails.rb
    lib/groonga/client/railtie.rb
    test/fixtures/rails4-mongoid/config/groonga_client.yml

  Added: lib/groonga-client-rails.rb (+21 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga-client-rails.rb    2016-03-21 22:39:30 +0900 (7954ec7)
@@ -0,0 +1,21 @@
+# Copyright (C) 2016  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 "groonga/client/rails/version"
+
+if defined?(Rails)
+  require "groonga/client/railtie"
+end

  Added: lib/groonga/client/railtie.rb (+60 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/client/railtie.rb    2016-03-21 22:39:30 +0900 (39dbb77)
@@ -0,0 +1,60 @@
+# Copyright (C) 2016  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 "groonga/client"
+
+module Groonga
+  class Client
+    # @private
+    class Railtie < ::Rails::Railtie
+      initializer "groonga-client.configure" do |app|
+        config_name = :groonga_client
+        config_path = Pathname(app.paths["config"].existent.first)
+        yaml_path = config_path + "#{config_name}.yml"
+        unless yaml_path.exist?
+          yaml_path.open("w") do |yaml|
+            yaml.puts(<<-YAML)
+default: &default
+  protocol: http
+  # protocol: https
+  host: 127.0.0.1
+  port: 10041
+  # user: alice
+  # password: secret
+  read_timeout: -1
+  # read_timeout: 3
+  backend: synchronous
+
+development:
+  <<: *default
+
+test:
+  <<: *default
+  port: 20041
+
+production:
+  <<: *default
+  host: 127.0.0.1
+  read_timeout: 10
+            YAML
+          end
+        end
+        Groonga::Client.default_options =
+          app.config_for(:groonga_client).deep_symbolize_keys
+      end
+    end
+  end
+end

  Added: test/fixtures/rails4-mongoid/config/groonga_client.yml (+22 -0) 100644
===================================================================
--- /dev/null
+++ test/fixtures/rails4-mongoid/config/groonga_client.yml    2016-03-21 22:39:30 +0900 (807a647)
@@ -0,0 +1,22 @@
+default: &default
+  protocol: http
+  # protocol: https
+  host: 127.0.0.1
+  port: 10041
+  # user: alice
+  # password: secret
+  read_timeout: -1
+  # read_timeout: 3
+  backend: synchronous
+
+development:
+  <<: *default
+
+test:
+  <<: *default
+  port: 20041
+
+production:
+  <<: *default
+  host: 127.0.0.1
+  read_timeout: 10
-------------- next part --------------
HTML����������������������������...
Download 



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