scottburton11-tokyomapper 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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/tokyomapper.rb +75 -0
- data/test/test_helper.rb +10 -0
- data/test/tokyomapper_test.rb +7 -0
- metadata +64 -0
data/.document
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Scott Burton
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
= tokyomapper
|
|
2
|
+
|
|
3
|
+
TokyoMapper is an extremely lightweight ORM for TokyoCabinet. It stuffs your instance variables into a .tdb row, and loads them into new instances on #find. Nothing fancy!
|
|
4
|
+
|
|
5
|
+
== Example
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Elephant
|
|
9
|
+
include TokyoMapper
|
|
10
|
+
|
|
11
|
+
attr_accessor :trunk_length
|
|
12
|
+
|
|
13
|
+
def initialize(params)
|
|
14
|
+
@trunk_length = params[:trunk_length]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
elephant = Elephant.new(:trunk_length => "Super Long")
|
|
19
|
+
elephant.save
|
|
20
|
+
#=> true
|
|
21
|
+
# creates elephant.tdb unless it exists
|
|
22
|
+
|
|
23
|
+
Elephant.all
|
|
24
|
+
#=> [#<Elephant:0x18b8100 @trunk_length="Super Long"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
== Note on Patches/Pull Requests
|
|
29
|
+
|
|
30
|
+
* Fork the project.
|
|
31
|
+
* Make your feature addition or bug fix.
|
|
32
|
+
* Add tests for it. This is important so I don't break it in a
|
|
33
|
+
future version unintentionally.
|
|
34
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
35
|
+
(if you want to have your own version, that is fine but
|
|
36
|
+
bump version in a commit by itself I can ignore when I pull)
|
|
37
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
38
|
+
|
|
39
|
+
== Copyright
|
|
40
|
+
|
|
41
|
+
Copyright (c) 2009 Scott Burton. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "tokyomapper"
|
|
8
|
+
gem.summary = %Q{A succinct ORM for TokyoCabinet}
|
|
9
|
+
gem.description = %Q{TokyoMapper is a simple ORM for TokyoCabinet. Just 'include TokyoMapper' in your class and go! Requires the tokyocabinet-ruby bindings and the tokyocabinet package.}
|
|
10
|
+
gem.email = "scottburton11@gmail.com"
|
|
11
|
+
gem.homepage = "http://github.com/scottburton11/tokyomapper"
|
|
12
|
+
gem.authors = ["Scott Burton"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
rescue LoadError
|
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
require 'rake/testtask'
|
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
|
21
|
+
test.libs << 'lib' << 'test'
|
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
|
23
|
+
test.verbose = true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
require 'rcov/rcovtask'
|
|
28
|
+
Rcov::RcovTask.new do |test|
|
|
29
|
+
test.libs << 'test'
|
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
|
31
|
+
test.verbose = true
|
|
32
|
+
end
|
|
33
|
+
rescue LoadError
|
|
34
|
+
task :rcov do
|
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
task :default => :test
|
|
43
|
+
|
|
44
|
+
require 'rake/rdoctask'
|
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
|
46
|
+
if File.exist?('VERSION.yml')
|
|
47
|
+
config = YAML.load(File.read('VERSION.yml'))
|
|
48
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
|
49
|
+
else
|
|
50
|
+
version = ""
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
54
|
+
rdoc.title = "tokyomapper #{version}"
|
|
55
|
+
rdoc.rdoc_files.include('README*')
|
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
57
|
+
end
|
|
58
|
+
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
data/lib/tokyomapper.rb
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module TokyoMapper
|
|
2
|
+
include TokyoCabinet
|
|
3
|
+
|
|
4
|
+
module ClassMethods
|
|
5
|
+
|
|
6
|
+
def connection(&block)
|
|
7
|
+
if block_given?
|
|
8
|
+
begin
|
|
9
|
+
open_db
|
|
10
|
+
payload = yield db
|
|
11
|
+
rescue => e
|
|
12
|
+
puts "There was an error: #{e}"
|
|
13
|
+
ensure
|
|
14
|
+
close_db
|
|
15
|
+
end
|
|
16
|
+
return payload
|
|
17
|
+
else
|
|
18
|
+
db
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def db(&block)
|
|
23
|
+
@db ||= TokyoCabinet::TDB::new
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def open_db
|
|
27
|
+
db.open(self.db_name, TokyoCabinet::TDB::OWRITER | TokyoCabinet::TDB::OCREAT)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def close_db
|
|
31
|
+
db.close
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def all
|
|
35
|
+
connection do |db|
|
|
36
|
+
db.keys.map{|k| self.new(self.symbolize_keys(db.get(k)))}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def symbolize_keys(original_hash)
|
|
41
|
+
new_hash = {}
|
|
42
|
+
original_hash.each_pair do |k,v|
|
|
43
|
+
new_hash[k.to_sym] = v
|
|
44
|
+
end
|
|
45
|
+
return new_hash
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def stringify_keys(original_hash)
|
|
49
|
+
new_hash = {}
|
|
50
|
+
original_hash.each_pair do |k,v|
|
|
51
|
+
new_hash[k.to_s] = v
|
|
52
|
+
end
|
|
53
|
+
return new_hash
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def db_name
|
|
57
|
+
"#{self.name.downcase.pluralize}.tdb"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
module InstanceMethods
|
|
63
|
+
|
|
64
|
+
def save
|
|
65
|
+
self.class.connection { |db| db.put(db.genuid, self.class.stringify_keys(self.instance_values))}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.included(receiver)
|
|
71
|
+
receiver.extend ClassMethods
|
|
72
|
+
receiver.send :include, InstanceMethods
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: scottburton11-tokyomapper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Scott Burton
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-08-17 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: TokyoMapper is a simple ORM for TokyoCabinet. Just 'include TokyoMapper' in your class and go! Requires the tokyocabinet-ruby bindings and the tokyocabinet package.
|
|
17
|
+
email: scottburton11@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.rdoc
|
|
25
|
+
files:
|
|
26
|
+
- .document
|
|
27
|
+
- .gitignore
|
|
28
|
+
- LICENSE
|
|
29
|
+
- README.rdoc
|
|
30
|
+
- Rakefile
|
|
31
|
+
- VERSION
|
|
32
|
+
- lib/tokyomapper.rb
|
|
33
|
+
- test/test_helper.rb
|
|
34
|
+
- test/tokyomapper_test.rb
|
|
35
|
+
has_rdoc: false
|
|
36
|
+
homepage: http://github.com/scottburton11/tokyomapper
|
|
37
|
+
licenses:
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options:
|
|
40
|
+
- --charset=UTF-8
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: "0"
|
|
48
|
+
version:
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "0"
|
|
54
|
+
version:
|
|
55
|
+
requirements: []
|
|
56
|
+
|
|
57
|
+
rubyforge_project:
|
|
58
|
+
rubygems_version: 1.3.5
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 3
|
|
61
|
+
summary: A succinct ORM for TokyoCabinet
|
|
62
|
+
test_files:
|
|
63
|
+
- test/test_helper.rb
|
|
64
|
+
- test/tokyomapper_test.rb
|