Kouhei Sutou
null+****@clear*****
Fri Mar 21 14:59:37 JST 2014
Kouhei Sutou 2014-03-21 14:59:37 +0900 (Fri, 21 Mar 2014) New Revision: 45f3f1f62fd79ae3b876c98835c4df062e869275 https://github.com/droonga/fluent-plugin-droonga/commit/45f3f1f62fd79ae3b876c98835c4df062e869275 Message: Introduce ReplicaCollection It will have replica selecting feature that is placed in Catalog::Version2. Copied files: lib/droonga/catalog/replica_collection.rb (from lib/droonga/catalog/dataset.rb) Modified files: lib/droonga/catalog/dataset.rb test/unit/catalog/test_dataset.rb Modified: lib/droonga/catalog/dataset.rb (+2 -1) =================================================================== --- lib/droonga/catalog/dataset.rb 2014-03-21 14:51:11 +0900 (2b5355f) +++ lib/droonga/catalog/dataset.rb 2014-03-21 14:59:37 +0900 (3e670a7) @@ -14,6 +14,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require "droonga/catalog/schema" +require "droonga/catalog/replica_collection" module Droonga module Catalog @@ -51,7 +52,7 @@ module Droonga end def replicas - @data["replicas"] + @replicas ||= ReplicaCollection.new(@data["replicas"]) end end end Copied: lib/droonga/catalog/replica_collection.rb (+13 -28) 57% =================================================================== --- lib/droonga/catalog/dataset.rb 2014-03-21 14:51:11 +0900 (2b5355f) +++ lib/droonga/catalog/replica_collection.rb 2014-03-21 14:59:37 +0900 (f50bbbc) @@ -13,45 +13,30 @@ # 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 "droonga/catalog/schema" - module Droonga module Catalog - class Dataset - def initialize(name, data) - @name = name - @data = data - @schema = nil - end - - # provided for compatibility - def [](key) - @data[key] - end - - # provided for compatibility - def []=(key, value) - @data[key] = value - end + class ReplicaCollection + include Enumerable - def schema - @schema ||= Schema.new(@name, @data["schema"]) + def initialize(replicas) + @replicas = replicas end - def plugins - @data["plugins"] || [] + def each(&block) + @replicas.each(&block) end - def fact - @data["fact"] + def ==(other) + other.is_a?(self.class) and + to_a == other.to_a end - def n_workers - @data["nWorkers"] || 0 + def eql?(other) + self == other end - def replicas - @data["replicas"] + def hash + to_a.hash end end end Modified: test/unit/catalog/test_dataset.rb (+2 -1) =================================================================== --- test/unit/catalog/test_dataset.rb 2014-03-21 14:51:11 +0900 (828a8a7) +++ test/unit/catalog/test_dataset.rb 2014-03-21 14:59:37 +0900 (87cab44) @@ -90,7 +90,8 @@ class CatalogDatasetTest < Test::Unit::TestCase "replicas" => [], } dataset = create_dataset(data) - assert_equal([], dataset.replicas) + assert_equal(Droonga::Catalog::ReplicaCollection.new([]), + dataset.replicas) end end end -------------- next part -------------- HTML����������������������������... ダウンロード