rocksdb-ruby 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f9f74e6a1525fbea3aab80e530e7ef9d1d9d15c
4
+ data.tar.gz: 64bc98ff317ac26ea8af37e176ceda7f63a572ee
5
+ SHA512:
6
+ metadata.gz: fa4362a718bfce0623c94bfb0b4a877a841e67396190ed68482e23568383ff3cfca7e3a99f1b244c58c2fde92851dd14c268792f17fe4cf5d9121c66721cdc5c
7
+ data.tar.gz: 0a656290c3496a0f7425c4cb132b130a2aeda5d9fbb64136e0c201f7483a5684f8c438e148c9b440db614c824c8fdcaa9ea14e225ab50d9f207b64adc5fbbb26
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rocksdb-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Isamu Arimoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Rocksdb::Ruby
2
+
3
+ The rocksdb is a persistent in-process key-value store.
4
+ Read more about it here: http://rocksdb.org/
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rocksdb-ruby'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rocksdb-ruby
19
+
20
+ ## Usage
21
+
22
+ @rockdb = RocksDB.new "/tmp/file"
23
+
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+ task :build do
7
+ Dir.chdir('ext/rocksdb/') do
8
+ output = `ruby extconf.rb`
9
+ raise output unless $? == 0
10
+ output = `make`
11
+ raise output unless $? == 0
12
+ end
13
+ end
14
+
15
+ task :spec => :build
@@ -0,0 +1,20 @@
1
+ require "mkmf"
2
+
3
+ dir_config('rocksdb')
4
+
5
+ have_header('db.h')
6
+
7
+ have_library('rocksdb')
8
+
9
+ $LDFLAGS= " -lgflags -lz -lbz2"
10
+
11
+ #$CCFLAGS= " -DROCKSDB_PLATFORM_POSIX -DOS_MACOSX -DROCKSDB_ATOMIC_PRESENT -DGFLAGS -DZLIB -DBZIP2"
12
+ $CPPFLAGS << " -std=gnu++11 -DROCKSDB_PLATFORM_POSIX -DOS_MACOSX -DROCKSDB_ATOMIC_PRESENT -DGFLAGS -DZLIB -DBZIP2 "
13
+
14
+ #SHARED_CFLAGS=" -fPIC"
15
+ #SHARED_EXT=" dylib"
16
+ #SHARED_LDFLAGS=" -dynamiclib -install_name "
17
+
18
+
19
+ create_makefile("RocksDB")
20
+
@@ -0,0 +1,81 @@
1
+ #include "rocksdb/db.h"
2
+ #include <iostream>
3
+
4
+ extern "C" {
5
+
6
+ #include <stdio.h>
7
+ #include <ruby.h>
8
+
9
+ typedef VALUE (*METHOD)(...);
10
+
11
+ VALUE rocksdb_init(int argc, VALUE* argv, VALUE self);
12
+ VALUE rocksdb_put(VALUE self, VALUE v_key, VALUE v_value);
13
+ VALUE rocksdb_get(VALUE self, VALUE v_key);
14
+ VALUE rocksdb_delete(VALUE self, VALUE v_key);
15
+ VALUE rocksdb_close();
16
+
17
+
18
+ rocksdb::DB* db;
19
+
20
+ void Init_RocksDB(){
21
+
22
+ VALUE cRocksdb;
23
+
24
+ cRocksdb = rb_define_class("RocksDB", rb_cObject);
25
+ rb_define_private_method(cRocksdb, "initialize", (METHOD)rocksdb_init, -1);
26
+ rb_define_method(cRocksdb, "put", (METHOD)rocksdb_put, 2);
27
+ rb_define_method(cRocksdb, "get", (METHOD)rocksdb_get, 1);
28
+ rb_define_method(cRocksdb, "delete", (METHOD)rocksdb_delete, 1);
29
+ rb_define_method(cRocksdb, "close", (METHOD)rocksdb_close, 0);
30
+ }
31
+
32
+ VALUE rocksdb_init(int argc, VALUE* argv, VALUE self) {
33
+ VALUE v_db_file_name;
34
+
35
+ rb_scan_args(argc, argv, "01", &v_db_file_name);
36
+ Check_Type(v_db_file_name, T_STRING);
37
+ std::string db_file_name = std::string((char*)RSTRING_PTR(v_db_file_name));
38
+
39
+ rocksdb::Options options;
40
+ options.create_if_missing = true;
41
+ rocksdb::Status status = rocksdb::DB::Open(options, db_file_name, &db);
42
+
43
+ return status.ok() ? Qtrue : Qfalse;
44
+ }
45
+
46
+ VALUE rocksdb_put(VALUE self, VALUE v_key, VALUE v_value) {
47
+ Check_Type(v_key, T_STRING);
48
+ Check_Type(v_value, T_STRING);
49
+
50
+ std::string key = std::string((char*)RSTRING_PTR(v_key));
51
+ std::string value = std::string((char*)RSTRING_PTR(v_value));
52
+
53
+ rocksdb::Status status = db->Put(rocksdb::WriteOptions(), key, value);
54
+
55
+ return status.ok() ? Qtrue : Qfalse;
56
+ }
57
+
58
+ VALUE rocksdb_get(VALUE self, VALUE v_key){
59
+ Check_Type(v_key, T_STRING);
60
+
61
+ std::string key = std::string((char*)RSTRING_PTR(v_key));
62
+ std::string value;
63
+ db->Get(rocksdb::ReadOptions(), key, &value);
64
+
65
+ return rb_str_new(value.data(), value.size());
66
+ }
67
+
68
+ VALUE rocksdb_delete(VALUE self, VALUE v_key){
69
+ Check_Type(v_key, T_STRING);
70
+
71
+ std::string key = std::string((char*)RSTRING_PTR(v_key));
72
+ rocksdb::Status status = db->Delete(rocksdb::WriteOptions(), key);
73
+
74
+ return status.ok() ? Qtrue : Qfalse;
75
+ }
76
+
77
+ VALUE rocksdb_close(){
78
+ delete db;
79
+ return Qnil;
80
+ }
81
+ }
@@ -0,0 +1,7 @@
1
+ require "rocksdb/ruby/version"
2
+
3
+ module Rocksdb
4
+ module Ruby
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Rocksdb
2
+ module Ruby
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rocksdb/ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.extensions = ["ext/rocksdb/extconf.rb"]
8
+
9
+ spec.name = "rocksdb-ruby"
10
+ spec.version = Rocksdb::Ruby::VERSION
11
+ spec.authors = ["Isamu Arimoto"]
12
+ spec.email = ["v-iarimoto@uievolution.com"]
13
+ spec.description = %q{me}
14
+ spec.summary = %q{me}
15
+ spec.homepage = ""
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["ext", "lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/spec/db_spec.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require "RocksDB"
3
+
4
+ describe RocksDB do
5
+ before do
6
+ @rockdb = RocksDB.new "/tmp/file"
7
+ end
8
+
9
+ it 'should get data' do
10
+ @rockdb.put("test:read", "1")
11
+ @rockdb.get("test:read").should eq "1"
12
+ end
13
+
14
+ it 'should put data' do
15
+ @rockdb.put("test:put", "2").should be_true
16
+ @rockdb.get("test:put").should eq "2"
17
+ end
18
+
19
+ it 'should delete data' do
20
+ @rockdb.put("test:delete", "3")
21
+ @rockdb.get("test:delete").should eq "3"
22
+
23
+ @rockdb.delete("test:delete").should be_true
24
+ @rockdb.get("test:delete").should be_empty
25
+ end
26
+
27
+ after do
28
+ @rockdb.close
29
+ end
30
+
31
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $: << File.dirname(__FILE__) + '/../ext/rocksdb'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rocksdb-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Isamu Arimoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: me
56
+ email:
57
+ - v-iarimoto@uievolution.com
58
+ executables: []
59
+ extensions:
60
+ - ext/rocksdb/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - ext/rocksdb/extconf.rb
69
+ - ext/rocksdb/rocksdb_rb.cc
70
+ - lib/rocksdb/ruby.rb
71
+ - lib/rocksdb/ruby/version.rb
72
+ - rocksdb-ruby.gemspec
73
+ - spec/db_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - ext
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: me
100
+ test_files:
101
+ - spec/db_spec.rb
102
+ - spec/spec_helper.rb