Navigation Menu

Skip to content

Commit

Permalink
Introduce Catalog::Dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
darashi committed Feb 27, 2014
1 parent 3b151d0 commit 111d865
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
35 changes: 35 additions & 0 deletions lib/droonga/catalog/dataset.rb
@@ -0,0 +1,35 @@
# 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
# License version 2.1 as published by the Free Software Foundation.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

module Droonga
module Catalog
class Dataset
def initialize(name, data)
@name = name
@data = data
end

# provided for compatibility
def [](key)
@data[key]
end

# provided for compatibility
def []=(key, value)
@data[key] = value
end
end
end
end
4 changes: 3 additions & 1 deletion lib/droonga/catalog/version1.rb
Expand Up @@ -14,6 +14,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "droonga/catalog/base"
require "droonga/catalog/dataset"

module Droonga
module Catalog
Expand All @@ -36,7 +37,8 @@ def get_partitions(name)
device = @data["farms"][name]["device"]
pattern = Regexp.new("^#{name}\.")
results = {}
@data["datasets"].each do |dataset_name, dataset|
@data["datasets"].each do |dataset_name, dataset_data|
dataset = Dataset.new(dataset_name, dataset_data)
workers = dataset["workers"]
plugins = dataset["plugins"]
dataset["ring"].each do |key, part|
Expand Down
4 changes: 3 additions & 1 deletion lib/droonga/catalog/version2.rb
Expand Up @@ -14,6 +14,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "droonga/catalog/base"
require "droonga/catalog/dataset"

module Droonga
module Catalog
Expand All @@ -27,7 +28,8 @@ def slices(name)
device = "."
pattern = Regexp.new("^#{name}\.")
results = {}
@data["datasets"].each do |dataset_name, dataset|
@data["datasets"].each do |dataset_name, dataset_data|
dataset = Dataset.new(dataset_name, dataset_data)
n_workers = dataset["nWorkers"]
plugins = dataset["plugins"]
dataset["replicas"].each do |replica|
Expand Down
35 changes: 35 additions & 0 deletions test/unit/catalog/test_dataset.rb
@@ -0,0 +1,35 @@
# 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
# License version 2.1 as published by the Free Software Foundation.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "droonga/catalog/dataset"

class CatalogDatasetTest < Test::Unit::TestCase
private
def create_dataset(dataset_name, data)
Droonga::Catalog::Dataset.new(dataset_name, data)
end

class DatasetTest < self
def test_value
assert_equal(2,
create_dataset("dataset_name",
{
"nWorkers" => 2
}
)["nWorkers"]
)
end
end
end

0 comments on commit 111d865

Please sign in to comment.