YUKI Hiroshi
null+****@clear*****
Thu May 8 18:26:38 JST 2014
YUKI Hiroshi 2014-05-08 18:26:38 +0900 (Thu, 08 May 2014) New Revision: ae0a6d391364fc6d503c53866d14ddcb99b718a9 https://github.com/droonga/droonga-engine/commit/ae0a6d391364fc6d503c53866d14ddcb99b718a9 Message: Add Droonga::Catalog::LiveNodes class Copied files: lib/droonga/catalog/live_nodes.rb (from lib/droonga/catalog/base.rb) Modified files: lib/droonga/catalog/base.rb Modified: lib/droonga/catalog/base.rb (+2 -25) =================================================================== --- lib/droonga/catalog/base.rb 2014-05-08 18:14:41 +0900 (ccbd529) +++ lib/droonga/catalog/base.rb 2014-05-08 18:26:38 +0900 (482ae6f) @@ -18,8 +18,7 @@ require "zlib" require "time" require "droonga/error_messages" require "droonga/catalog/errors" -require "pathname" -require "json" +require "droonga/catalog/live_nodes" module Droonga module Catalog @@ -41,29 +40,7 @@ module Droonga end def live_nodes - @live_nodes ||= load_live_nodes - end - - private - def load_live_nodes - file = @options[:live_nodes_file] - return default_live_nodes unless file - - file = Pathname(file) - return default_live_nodes unless file.exist? - - contents = file.read - return default_live_nodes if contents.empty? - - begin - JSON.parse(contents).keys - rescue JSON::ParserError - default_live_nodes - end - end - - def default_live_nodes - {} + @live_nodes ||= LiveNodes.new(@options[:live_nodes_file]) end end end Copied: lib/droonga/catalog/live_nodes.rb (+14 -32) 52% =================================================================== --- lib/droonga/catalog/base.rb 2014-05-08 18:14:41 +0900 (ccbd529) +++ lib/droonga/catalog/live_nodes.rb 2014-05-08 18:26:38 +0900 (31edf9e) @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 Droonga Project +# Copyright (C) 2014 Droonga Project # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -13,56 +13,38 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -require "digest/sha1" -require "zlib" -require "time" -require "droonga/error_messages" -require "droonga/catalog/errors" require "pathname" require "json" module Droonga module Catalog - class Base + class LiveNodes attr_reader :path, :base_path - def initialize(data, path, options={}) - @data = data - @path = path - @options = options - @base_path = File.dirname(path) + def initialize(list_file) + @list_file = Pathname(list_file) + @list = parse_list_file end - def have_dataset?(name) - datasets.key?(name) - end - - def dataset(name) - datasets[name] - end - - def live_nodes - @live_nodes ||= load_live_nodes + def live?(node) + @list.key?(node) end private - def load_live_nodes - file = @options[:live_nodes_file] - return default_live_nodes unless file - - file = Pathname(file) - return default_live_nodes unless file.exist? + def parse_list_file + return default_list unless @list_file + return default_list unless @list_file.exist? - contents = file.read - return default_live_nodes if contents.empty? + contents = @list_file.read + return default_list if contents.empty? begin JSON.parse(contents).keys rescue JSON::ParserError - default_live_nodes + default_list end end - def default_live_nodes + def default_list {} end end -------------- next part -------------- HTML����������������������������...Download