[Groonga-commit] droonga/droonga-engine at 4c72dc2 [master] Simplify

Back to archive index

Kouhei Sutou null+****@clear*****
Mon May 26 17:28:47 JST 2014


Kouhei Sutou	2014-05-26 17:28:47 +0900 (Mon, 26 May 2014)

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

  Message:
    Simplify

  Modified files:
    lib/droonga/live_nodes_list_loader.rb
    lib/droonga/live_nodes_list_observer.rb

  Modified: lib/droonga/live_nodes_list_loader.rb (+6 -8)
===================================================================
--- lib/droonga/live_nodes_list_loader.rb    2014-05-26 17:17:42 +0900 (9cd36be)
+++ lib/droonga/live_nodes_list_loader.rb    2014-05-26 17:28:47 +0900 (6d5fee2)
@@ -18,22 +18,20 @@ require "json"
 
 module Droonga
   class LiveNodesListLoader
-    def initialize(file_path)
-      @file_path = file_path
+    def initialize(path)
+      @path = path
     end
 
     def load
-      list_file = Pathname(@file_path)
-      list = parse_list_file(list_file)
+      list = parse
       list.keys
     end
 
     private
-    def parse_list_file(list_file)
-      return default_list unless list_file
-      return default_list unless list_file.exist?
+    def parse
+      return default_list unles****@path*****?
 
-      contents = list_file.read
+      contents =****@path*****
       return default_list if contents.empty?
 
       begin

  Modified: lib/droonga/live_nodes_list_observer.rb (+13 -15)
===================================================================
--- lib/droonga/live_nodes_list_observer.rb    2014-05-26 17:17:42 +0900 (d08eefe)
+++ lib/droonga/live_nodes_list_observer.rb    2014-05-26 17:28:47 +0900 (dc5a543)
@@ -27,16 +27,18 @@ module Droonga
     attr_accessor :on_update
 
     def initialize
-      FileUtils.mkdir_p(directory_path)
-      @listener = Listen.to(directory_path) do |modified, added, removed|
-        if added.include?(file_path) or
-             modified.include?(file_path)
-          load_list!
-        end
-      end
     end
 
     def start
+      file_name = path.to_s
+      directory = path.dirname.to_s
+      FileUtils.mkdir_p(directory)
+      @listener = Listen.to(directory) do |modified, added, removed|
+        if added.include?(file_name) or
+             modified.include?(file_name)
+          load_list!
+        end
+      end
       @listener.start
     end
 
@@ -46,18 +48,14 @@ module Droonga
 
     LIST_FILE_NAME = "live-nodes.json"
 
-    def file_path
-      (Droonga::Path.state + LIST_FILE_NAME).to_s
-    end
-
-    def directory_path
-      File.dirname(file_path)
+    def path
+      Droonga::Path.state + LIST_FILE_NAME
     end
 
     def load_list!
-      loader = LiveNodesListLoader.new(file_path)
+      loader = LiveNodesListLoader.new(path)
       live_nodes = loader.load
-      logger.info("loaded", :path => file_path, :live_nodes => live_nodes)
+      logger.info("loaded", :path => path.to_s, :live_nodes => live_nodes)
 
       on_update.call(live_nodes) if on_update
     end
-------------- next part --------------
HTML����������������������������...
Download 



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