[Groonga-commit] droonga/droonga-engine at ef36b09 [buffered-forward] droonga-engine: fix a bug that --base-dir doesn't effect to config path

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 5 12:50:13 JST 2015


Kouhei Sutou	2015-01-05 12:50:13 +0900 (Mon, 05 Jan 2015)

  New Revision: ef36b099ad58b93143a4ba0da06c3a649e4b53ee
  https://github.com/droonga/droonga-engine/commit/ef36b099ad58b93143a4ba0da06c3a649e4b53ee

  Message:
    droonga-engine: fix a bug that --base-dir doesn't effect to config path
    
    `#{BASE_DIR}/droonga-engine.yaml` is read by this change.

  Modified files:
    lib/droonga/command/droonga_engine.rb

  Modified: lib/droonga/command/droonga_engine.rb (+47 -27)
===================================================================
--- lib/droonga/command/droonga_engine.rb    2014-12-26 17:59:48 +0900 (69784cb)
+++ lib/droonga/command/droonga_engine.rb    2015-01-05 12:50:13 +0900 (6670056)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014 Droonga Project
+# Copyright (C) 2014-2015 Droonga Project
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -113,66 +113,73 @@ module Droonga
       end
 
       class Configuration
-        attr_reader :host, :port, :tag, :log_file, :pid_file_path
         attr_reader :ready_notify_fd
         def initialize
-          config = load_config
+          @config = nil
 
-          @host = config["host"] || Address::DEFAULT_HOST
-          @port = config["port"] || Address::DEFAULT_PORT
-          @tag  = config["tag"]  || Address::DEFAULT_TAG
+          @host = nil
+          @port = nil
+          @tag  = nil
 
           @log_file        = nil
-          @daemon          = false
+          @daemon          = nil
           @pid_file_path   = nil
           @ready_notify_fd = nil
+        end
 
-          if have_config_file?
-            self.pid_file_path = config["pid_file"] if config["pid_file"]
-            self.log_file  = config["log_file"] || Path.default_log_file
-            self.log_level = config["log_level"] if config.include?("log_level")
-          end
+        def engine_name
+          "#{host}:#{port}/#{tag}"
         end
 
-        def have_config_file?
-          File.exist?(Path.config)
+        def address_family
+          ip_address = IPAddr.new(IPSocket.getaddress(host))
+          ip_address.family
         end
 
-        def load_config
-          if have_config_file?
-            YAML.load_file(Path.config)
-          else
-            {}
-          end
+        def host
+          @host || config["host"] || Address::DEFAULT_HOST
         end
 
-        def engine_name
-          "#{@host}:#{@port}/#{@tag}"
+        def port
+          @port || config["port"] || Address::DEFAULT_PORT
         end
 
-        def address_family
-          ip_address = IPAddr.new(IPSocket.getaddress(@host))
-          ip_address.family
+        def tag
+          @port || config["tag"] || Address::DEFAULT_TAG
         end
 
         def log_level
-          ENV["DROONGA_LOG_LEVEL"] || Logger::Level.default
+          ENV["DROONGA_LOG_LEVEL"] || config["log_level"] || Logger::Level.default
         end
 
         def log_level=(level)
           ENV["DROONGA_LOG_LEVEL"] = level
         end
 
+        def log_file
+          file = @log_file || config["log_file"] || Path.default_log_file
+          File.expand_path(file)
+        end
+
         def log_file=(file)
           @log_file = File.expand_path(file)
         end
 
+        def pid_file_path
+          path = @pid_file_path || config["pid_file"]
+          return nil if path.nil?
+          Pathname.new(path.to_s).expand_path
+        end
+
         def pid_file_path=(path)
           @pid_file_path = Pathname.new(path).expand_path
         end
 
         def daemon?
-          @daemon
+          daemon = @daemon
+          daemon = config["daemon"] if daemon.nil?
+          daemon = false if daemon.nil?
+          daemon
         end
 
         def to_command_line
@@ -199,6 +206,19 @@ module Droonga
         end
 
         private
+        def config
+          @config ||= load_config
+        end
+
+        def load_config
+          config = Path.config
+          if config.exist?
+            YAML.load_file(config)
+          else
+            {}
+          end
+        end
+
         def add_connection_options(parser)
           parser.separator("")
           parser.separator("Connection:")
-------------- next part --------------
HTML����������������������������...
Download 



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