tokyo_wrapper 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +23 -0
- data/lib/tokyo_wrapper/table.rb +7 -3
- data/spec/fixtures/rails.png +0 -0
- data/spec/fixtures/temp.txt +2 -0
- data/spec/tokyo_wrapper/table_spec.rb +105 -0
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -10,6 +10,29 @@
|
|
10
10
|
rufus-tokyo is "ffi based ruby library to access Tokyo Cabinet and Tokyo Tyrant" by John Mettraux
|
11
11
|
(Copyright (c) 2009-2010, see http://github.com/jmettraux/rufus-tokyo/blob/master/LICENSE.txt).
|
12
12
|
|
13
|
+
== Basic underlying philosophy
|
14
|
+
|
15
|
+
1. Preserve the functionality and behaviour of rufus-tokyo.
|
16
|
+
|
17
|
+
1-1. No fork of rufus-tokyo.
|
18
|
+
|
19
|
+
1-2. This gem doesn't open rufus-tokyo class and add a functionality there.
|
20
|
+
It is developed as a pure wrapper.
|
21
|
+
|
22
|
+
1-3. The minimum or no exception handling of its own is done.
|
23
|
+
All the exceptions should directly come from rufus-tokyo, so that usage of this gem doesn't
|
24
|
+
interfere the usage of rufus-tokyo to access Tokyo Cabinet.
|
25
|
+
(Of course, as found necessary, this gem raises its own exception but it should be minimum.)
|
26
|
+
|
27
|
+
2. The data are used in Hash format.
|
28
|
+
|
29
|
+
2-1. This gem is not meant to be a mapper to Object like Object-Relational Mapping.
|
30
|
+
Comment from the author (tadatoshi):
|
31
|
+
"I'm using Ruby on Rails most of the time. I'm thinking of using DataMapper for all the
|
32
|
+
Object-Relational Mappings when Ruby on Rails 3.0 becomes available.
|
33
|
+
I don't know much about DataMapper for Tokyo Cabinet so I cannot make a comment about it.
|
34
|
+
But at least, I'm thinking of using this gem only when I want to use the data in Hash format."
|
35
|
+
|
13
36
|
== Required Ruby Gems
|
14
37
|
|
15
38
|
rufus-tokyo 1.0.1 or above.
|
data/lib/tokyo_wrapper/table.rb
CHANGED
@@ -51,10 +51,14 @@ module TokyoWrapper
|
|
51
51
|
@table.query
|
52
52
|
end
|
53
53
|
|
54
|
-
def find(id)
|
55
|
-
|
54
|
+
def find(id, options = {})
|
55
|
+
if !options.empty? && options[:pk_included] == true
|
56
|
+
@table[id.to_s].merge({:pk => id.to_s})
|
57
|
+
else
|
58
|
+
@table[id.to_s]
|
59
|
+
end
|
56
60
|
end
|
57
|
-
|
61
|
+
|
58
62
|
def all_by_key_value(key, value)
|
59
63
|
@table.query do |query|
|
60
64
|
query.add key, :equals, value
|
Binary file
|
@@ -139,6 +139,40 @@ describe TokyoWrapper::Table do
|
|
139
139
|
|
140
140
|
end
|
141
141
|
|
142
|
+
context "Find" do
|
143
|
+
|
144
|
+
it "should find a row with a given id" do
|
145
|
+
|
146
|
+
begin
|
147
|
+
write_table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
|
148
|
+
|
149
|
+
data_hash = {"street" => "1111 Main",
|
150
|
+
"city" => "Montreal",
|
151
|
+
"notes" => "Some notes"}
|
152
|
+
id = write_table.add(data_hash)
|
153
|
+
ensure
|
154
|
+
write_table.close unless write_table.nil?
|
155
|
+
end
|
156
|
+
|
157
|
+
begin
|
158
|
+
read_table = TokyoWrapper::Table.create_with_read_non_locking(@table_file)
|
159
|
+
|
160
|
+
read_table.find(id).should == {"street" => "1111 Main",
|
161
|
+
"city" => "Montreal",
|
162
|
+
"notes" => "Some notes"}
|
163
|
+
read_table.find(id, :pk_included => true).should == {:pk => id.to_s,
|
164
|
+
"street" => "1111 Main",
|
165
|
+
"city" => "Montreal",
|
166
|
+
"notes" => "Some notes"}
|
167
|
+
|
168
|
+
ensure
|
169
|
+
read_table.close unless read_table.nil?
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
142
176
|
context "Find all" do
|
143
177
|
|
144
178
|
it "should find all the rows that have a given value" do
|
@@ -192,4 +226,75 @@ describe TokyoWrapper::Table do
|
|
192
226
|
|
193
227
|
end
|
194
228
|
|
229
|
+
context "store file content" do
|
230
|
+
|
231
|
+
it "should store the content of the specified text file" do
|
232
|
+
|
233
|
+
begin
|
234
|
+
write_table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
|
235
|
+
|
236
|
+
temp_file_content = open(File.expand_path(File.dirname(__FILE__) + '/../fixtures/temp.txt')).read
|
237
|
+
|
238
|
+
data_hash = {"filename" => "temp.txt",
|
239
|
+
"content_type" => "text/plain",
|
240
|
+
"size" => File.size(File.expand_path(File.dirname(__FILE__) + '/../fixtures/temp.txt')),
|
241
|
+
"file_data" => temp_file_content}
|
242
|
+
id = write_table.add(data_hash)
|
243
|
+
|
244
|
+
ensure
|
245
|
+
write_table.close unless write_table.nil?
|
246
|
+
end
|
247
|
+
|
248
|
+
begin
|
249
|
+
read_table = TokyoWrapper::Table.create_with_read_non_locking(@table_file)
|
250
|
+
|
251
|
+
read_table.find(id)["filename"].should == "temp.txt"
|
252
|
+
read_table.find(id)["content_type"].should == "text/plain"
|
253
|
+
read_table.find(id)["size"].should == "79"
|
254
|
+
read_table.find(id)["file_data"].should == "This is for testing storing the content of the file. \nDon't modify the content."
|
255
|
+
ensure
|
256
|
+
read_table.close unless read_table.nil?
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should store the content of the specified image file" do
|
262
|
+
|
263
|
+
begin
|
264
|
+
write_table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
|
265
|
+
|
266
|
+
image_file_content = open(File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails.png')).read
|
267
|
+
|
268
|
+
data_hash = {"filename" => "rails.png",
|
269
|
+
"content_type" => "image/png",
|
270
|
+
"size" => File.size(File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails.png')),
|
271
|
+
"file_data" => image_file_content}
|
272
|
+
id = write_table.add(data_hash)
|
273
|
+
|
274
|
+
ensure
|
275
|
+
write_table.close unless write_table.nil?
|
276
|
+
end
|
277
|
+
|
278
|
+
begin
|
279
|
+
read_table = TokyoWrapper::Table.create_with_read_non_locking(@table_file)
|
280
|
+
|
281
|
+
read_table.find(id)["filename"].should == "rails.png"
|
282
|
+
read_table.find(id)["content_type"].should == "image/png"
|
283
|
+
read_table.find(id)["size"].should == "1787"
|
284
|
+
|
285
|
+
file_for_retrieved_content = File.new(File.expand_path(File.dirname(__FILE__) + '/../fixtures/retrieved_rails.png'), "w")
|
286
|
+
file_for_retrieved_content.write(read_table.find(id)["file_data"])
|
287
|
+
file_for_retrieved_content.close
|
288
|
+
File.exists?(File.expand_path(File.dirname(__FILE__) + '/../fixtures/retrieved_rails.png')).should be_true
|
289
|
+
File.size(File.expand_path(File.dirname(__FILE__) + '/../fixtures/retrieved_rails.png')).should == File.size(File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails.png'))
|
290
|
+
|
291
|
+
ensure
|
292
|
+
File.delete(File.expand_path(File.dirname(__FILE__) + '/../fixtures/retrieved_rails.png')) if File.exists?(File.expand_path(File.dirname(__FILE__) + '/../fixtures/retrieved_rails.png'))
|
293
|
+
read_table.close unless read_table.nil?
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
195
300
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tokyo_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tadatoshi Takahashi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-29 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -29,6 +29,8 @@ files:
|
|
29
29
|
- lib/tokyo_wrapper.rb
|
30
30
|
- Rakefile
|
31
31
|
- README.rdoc
|
32
|
+
- spec/fixtures/rails.png
|
33
|
+
- spec/fixtures/temp.txt
|
32
34
|
- spec/macros/rufus_tokyo_macros.rb
|
33
35
|
- spec/spec_helper.rb
|
34
36
|
- spec/tokyo_cabinet_files/table.tct
|