tokyo_wrapper 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +41 -0
- data/Rakefile +3 -0
- data/init.rb +1 -0
- data/lib/tokyo_wrapper.rb +2 -0
- data/lib/tokyo_wrapper/table.rb +53 -0
- data/spec/macros/rufus_tokyo_macros.rb +11 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/tokyo_cabinet_files/table.tct +0 -0
- data/spec/tokyo_wrapper/table_spec.rb +77 -0
- metadata +69 -0
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= Tokyo Wrapper
|
2
|
+
|
3
|
+
Ruby gem with the code with the convenient methods written on the top of rufus-tokyo.
|
4
|
+
|
5
|
+
It is extracted from the code I frequently use when using rufus-tokyo to access Tokyo Cabinet.
|
6
|
+
|
7
|
+
For example, for table, I always add a row with unique id so I always use generate_unique_id method. By wrapping the call to this method, the code that is using the rufus/tokyo doesn't get cluttered.
|
8
|
+
|
9
|
+
rufus-tokyo is "ffi based ruby library to access Tokyo Cabinet and Tokyo Tyrant" by John Mettraux (Copyright (c) 2009-2010, see http://github.com/jmettraux/rufus-tokyo/blob/master/LICENSE.txt).
|
10
|
+
|
11
|
+
== Required Ruby Gems
|
12
|
+
|
13
|
+
rufus-tokyo 1.0.1 or above.
|
14
|
+
|
15
|
+
sudo gem install rufus-tokyo --source http://gemcutter.org
|
16
|
+
|
17
|
+
== Install
|
18
|
+
|
19
|
+
sudo gem install tokyo_wrapper --source http://gemcutter.org
|
20
|
+
|
21
|
+
== Licence
|
22
|
+
|
23
|
+
Copyright (c) 2010, Tadatoshi Takahashi
|
24
|
+
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
26
|
+
of this software and associated documentation files (the "Software"), to deal
|
27
|
+
in the Software without restriction, including without limitation the rights
|
28
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
29
|
+
copies of the Software, and to permit persons to whom the Software is
|
30
|
+
furnished to do so, subject to the following conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be included in
|
33
|
+
all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
36
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
37
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
38
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
39
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
40
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
41
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tokyo_wrapper'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module TokyoWrapper
|
2
|
+
|
3
|
+
class Table
|
4
|
+
|
5
|
+
def initialize(table)
|
6
|
+
@table = table
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create_with_create_write_non_blocking_lock(file)
|
10
|
+
table = Rufus::Tokyo::Table.new(File.expand_path(file), :mode => "cwf")
|
11
|
+
self.new(table)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create_with_write_non_blocking_lock(file)
|
15
|
+
table = Rufus::Tokyo::Table.new(File.expand_path(file), :mode => "wf")
|
16
|
+
self.new(table)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create_with_read_non_locking(file)
|
20
|
+
table = Rufus::Tokyo::Table.new(File.expand_path(file), :mode => "re")
|
21
|
+
self.new(table)
|
22
|
+
end
|
23
|
+
|
24
|
+
def close
|
25
|
+
@table.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(params = {})
|
29
|
+
id = @table.generate_unique_id
|
30
|
+
@table[id] = params
|
31
|
+
id
|
32
|
+
end
|
33
|
+
|
34
|
+
def update(id, params)
|
35
|
+
if !@table[id.to_s].nil? && !@table[id.to_s].empty?
|
36
|
+
@table[id.to_s] = @table[id.to_s].merge(params)
|
37
|
+
true
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def all
|
44
|
+
@table.query
|
45
|
+
end
|
46
|
+
|
47
|
+
def find(id)
|
48
|
+
@table[id.to_s]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe TokyoWrapper::Table do
|
4
|
+
include RufusTokyoMacros
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@table_file = File.expand_path(File.dirname(__FILE__) + '/../tokyo_cabinet_files/table.tct')
|
8
|
+
clear_table(@table_file)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
clear_table(@table_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Add" do
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
@table.close
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should add data" do
|
26
|
+
|
27
|
+
data_hash = {"street" => "1111 Main",
|
28
|
+
"city" => "Montreal",
|
29
|
+
"notes" => "Some notes"}
|
30
|
+
id = @table.add(data_hash)
|
31
|
+
|
32
|
+
@table.all.should == [{:pk => id.to_s,
|
33
|
+
"street" => "1111 Main",
|
34
|
+
"city" => "Montreal",
|
35
|
+
"notes" => "Some notes"}]
|
36
|
+
|
37
|
+
@table.find(id).should == {"street" => "1111 Main",
|
38
|
+
"city" => "Montreal",
|
39
|
+
"notes" => "Some notes"}
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context "Update" do
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
@table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:each) do
|
52
|
+
@table.close
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should update data" do
|
56
|
+
|
57
|
+
data_hash = {"street" => "1111 Main",
|
58
|
+
"city" => "Montreal",
|
59
|
+
"notes" => "Some notes"}
|
60
|
+
id = @table.add(data_hash)
|
61
|
+
|
62
|
+
@table.find(id).should == {"street" => "1111 Main",
|
63
|
+
"city" => "Montreal",
|
64
|
+
"notes" => "Some notes"}
|
65
|
+
|
66
|
+
result = @table.update(id, "notes" => "Recently situation has been changed.")
|
67
|
+
|
68
|
+
result.should be_true
|
69
|
+
@table.find(id).should == {"street" => "1111 Main",
|
70
|
+
"city" => "Montreal",
|
71
|
+
"notes" => "Recently situation has been changed."}
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tokyo_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tadatoshi Takahashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-17 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Collection of convenient methods written on the top of rufus/tokyo to access Tokyo Cabinet
|
17
|
+
email: tadatoshi.3.takahashi@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- lib/tokyo_wrapper.rb
|
25
|
+
files:
|
26
|
+
- init.rb
|
27
|
+
- lib/tokyo_wrapper/table.rb
|
28
|
+
- lib/tokyo_wrapper.rb
|
29
|
+
- Rakefile
|
30
|
+
- README.rdoc
|
31
|
+
- spec/macros/rufus_tokyo_macros.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
- spec/tokyo_cabinet_files/table.tct
|
34
|
+
- spec/tokyo_wrapper/table_spec.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/tadatoshi/tokyo_wrapper
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --line-numbers
|
42
|
+
- --inline-source
|
43
|
+
- --title
|
44
|
+
- Tokyo Wrapper
|
45
|
+
- --main
|
46
|
+
- README.rdoc
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "1.2"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: tokyo_wrapper
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Collection of convenient methods written on the top of rufus/tokyo to access Tokyo Cabinet
|
68
|
+
test_files: []
|
69
|
+
|