riak-shim 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -8
- data/.travis.yml +10 -0
- data/README.md +49 -23
- data/lib/riak-shim/persistable.rb +14 -5
- data/lib/riak-shim/store.rb +3 -5
- data/lib/riak-shim/version.rb +1 -1
- data/lib/riak-shim.rb +0 -1
- data/riak-shim.gemspec +8 -3
- metadata +140 -112
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -6,6 +6,9 @@ appropriate prefix.
|
|
6
6
|
|
7
7
|
Riak is a database from the good people at Basho. Check it out: http://basho.com/products/riak-overview/
|
8
8
|
|
9
|
+
[![Build Status](https://secure.travis-ci.org/mkb/riak-shim.png?branch=master)](http://travis-ci.org/mkb/riak-shim)
|
10
|
+
|
11
|
+
|
9
12
|
## Installation
|
10
13
|
|
11
14
|
Add this line to your application's Gemfile:
|
@@ -24,34 +27,58 @@ Or install it yourself as:
|
|
24
27
|
|
25
28
|
Create a config/database.yml containing the details of your Riak like so:
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
development: &default
|
31
|
+
bucket_prefix: dev_
|
32
|
+
host: localhost
|
33
|
+
http_port: 8098
|
34
|
+
|
35
|
+
test:
|
36
|
+
<<: *default
|
37
|
+
bucket_prefix: test_
|
38
|
+
|
39
|
+
## Converting a model to use Riak
|
40
|
+
|
41
|
+
In any class you wish to persist, you must include the module:
|
42
|
+
|
43
|
+
require 'riak-shim'
|
44
|
+
include Riak::Shim::Persistable
|
31
45
|
|
32
|
-
|
33
|
-
|
34
|
-
bucket_prefix: test_
|
46
|
+
Then, write a #to_hash method which returns a hash representing your object (and consequently, what you are
|
47
|
+
going to store):
|
35
48
|
|
36
|
-
|
37
|
-
|
49
|
+
def to_hash
|
50
|
+
# Return hashified version of your class
|
51
|
+
end
|
38
52
|
|
39
|
-
|
40
|
-
# Return hashified version of your class
|
41
|
-
end
|
53
|
+
You'll use Class#from_hash to create an instance from the hash which was pulled from Riak:
|
42
54
|
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
def self.from_hash(data)
|
56
|
+
your_obj = new
|
57
|
+
your_obj.foo = data['foo']
|
58
|
+
# Return a fresh instance of your class populated by the hash provided
|
59
|
+
return your_obj
|
60
|
+
end
|
46
61
|
|
47
|
-
|
48
|
-
|
49
|
-
# Return an empty Array if you don't know what this means. :)
|
50
|
-
end
|
62
|
+
You can now save instances of yoru class by calling #save and later retrieve them from Riak
|
63
|
+
by calling...
|
51
64
|
|
52
|
-
|
65
|
+
YourClass.for_key(key)
|
53
66
|
|
54
|
-
|
67
|
+
### Secondary indexes
|
68
|
+
|
69
|
+
Secondary indexes in Riak allow you to query based on the contents of a particular field. Define
|
70
|
+
YourClass#fields_to_index and return the names of any fields you wish to query on. When you #save
|
71
|
+
an instance of YourClass, riak-shim will populate a secondary index for that field.
|
72
|
+
|
73
|
+
def fields_to_index
|
74
|
+
# Return an Array of hash keys you would like placed into a secondary index.
|
75
|
+
# Return an empty Array if you don't know what this means. :)
|
76
|
+
end
|
77
|
+
|
78
|
+
You can now retrieve records based on the content of those fields by calling...
|
79
|
+
The `for_index` method retrieves all records whose value for the given index matches.
|
80
|
+
|
81
|
+
YourClass.for_index(index_name, value)
|
55
82
|
|
56
83
|
Where `index_name` is what you defined in `fields_to_index` plus the suffix "_bin" .
|
57
84
|
|
@@ -59,6 +86,7 @@ The `value` is what you want to look up.
|
|
59
86
|
|
60
87
|
Return value is an Array of instances of your class matching the query.
|
61
88
|
|
89
|
+
|
62
90
|
## Contributing
|
63
91
|
|
64
92
|
1. Fork it
|
@@ -69,7 +97,5 @@ Return value is an Array of instances of your class matching the query.
|
|
69
97
|
|
70
98
|
## TODOS
|
71
99
|
|
72
|
-
- #from_hash does not work as advertised
|
73
|
-
- Implement a #for_key lookup method
|
74
100
|
- Examples directory
|
75
101
|
- Revisit tests
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Riak
|
2
2
|
module Shim
|
3
|
-
|
4
3
|
module Persistable
|
5
4
|
attr_writer :store
|
6
5
|
attr_accessor :key
|
@@ -50,11 +49,11 @@ module Riak
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def bucket_name
|
53
|
-
myclass =
|
52
|
+
myclass = de_camel(self.to_s)
|
54
53
|
"#{store.bucket_prefix}#{myclass}"
|
55
54
|
end
|
56
55
|
|
57
|
-
def
|
56
|
+
def de_camel(classname)
|
58
57
|
classname.gsub(/::/, '__').
|
59
58
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
60
59
|
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
@@ -66,9 +65,19 @@ module Riak
|
|
66
65
|
return store.bucket(bucket_name)
|
67
66
|
end
|
68
67
|
|
68
|
+
def for_key(key)
|
69
|
+
begin
|
70
|
+
raw = bucket.get(key)
|
71
|
+
data = raw.data
|
72
|
+
from_hash(data)
|
73
|
+
rescue Riak::HTTPFailedRequest
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
69
78
|
def for_index(index, value)
|
70
79
|
bucket.get_index(index, value).map do |key|
|
71
|
-
|
80
|
+
for_key(key)
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
@@ -82,4 +91,4 @@ module Riak
|
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
85
|
-
end
|
94
|
+
end
|
data/lib/riak-shim/store.rb
CHANGED
@@ -3,10 +3,9 @@ require 'uuidtools'
|
|
3
3
|
|
4
4
|
module Riak
|
5
5
|
module Shim
|
6
|
-
|
7
6
|
class Store
|
8
7
|
attr_writer :config_location
|
9
|
-
|
8
|
+
attr_writer :riak
|
10
9
|
|
11
10
|
def config
|
12
11
|
env = ENV['RACK_ENV'] || 'test'
|
@@ -24,7 +23,7 @@ module Riak
|
|
24
23
|
def bucket_prefix
|
25
24
|
return config['bucket_prefix']
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def riak
|
29
28
|
@riak ||= Riak::Client.new(:http_backend => :Excon,
|
30
29
|
:nodes => [{:host => config['host'], :http_port => config['http_port']}])
|
@@ -34,6 +33,5 @@ module Riak
|
|
34
33
|
riak.bucket(name)
|
35
34
|
end
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
|
-
end
|
37
|
+
end
|
data/lib/riak-shim/version.rb
CHANGED
data/lib/riak-shim.rb
CHANGED
data/riak-shim.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
require File.expand_path('../lib/riak-shim/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Michael Brodhead
|
5
|
+
gem.authors = ["Michael Brodhead, Shai Rosenfeld, and Larry Diehl"]
|
6
6
|
gem.email = ["mkb@engineyard.com"]
|
7
|
-
gem.description = %q{Riak shim for bucket
|
7
|
+
gem.description = %q{Riak shim for bucket naming and config.}
|
8
8
|
gem.summary = %q{A tiny shim between you and riak-client. Reads config/database.yml and generates sensible bucket names.}
|
9
9
|
gem.homepage = "https://github.com/mkb/riak-shim"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.
|
12
|
+
gem.files.reject! {|f| f =~ %r{^vendor}}
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.name = "riak-shim"
|
15
15
|
gem.require_paths = ["lib"]
|
@@ -22,4 +22,9 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_development_dependency "rspec"
|
23
23
|
gem.add_development_dependency "guard"
|
24
24
|
gem.add_development_dependency "guard-rspec"
|
25
|
+
|
26
|
+
if RUBY_PLATFORM.include? 'darwin'
|
27
|
+
gem.add_development_dependency 'growl'
|
28
|
+
gem.add_development_dependency 'rb-fsevent'
|
29
|
+
end
|
25
30
|
end
|
metadata
CHANGED
@@ -1,117 +1,153 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: riak-shim
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
- Michael Brodhead
|
7
|
+
authors:
|
8
|
+
- Michael Brodhead, Shai Rosenfeld, and Larry Diehl
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: riak-client
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
hash: 3
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: uuidtools
|
36
23
|
prerelease: false
|
37
|
-
|
38
|
-
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: uuidtools
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rake
|
50
39
|
prerelease: false
|
51
|
-
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
60
54
|
type: :development
|
61
|
-
version_requirements: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rspec
|
64
55
|
prerelease: false
|
65
|
-
|
66
|
-
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
74
70
|
type: :development
|
75
|
-
version_requirements: *id004
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: guard
|
78
71
|
prerelease: false
|
79
|
-
|
80
|
-
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
88
86
|
type: :development
|
89
|
-
|
90
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
91
95
|
name: guard-rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
92
103
|
prerelease: false
|
93
|
-
|
94
|
-
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: growl
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
102
118
|
type: :development
|
103
|
-
|
104
|
-
|
105
|
-
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rb-fsevent
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Riak shim for bucket naming and config.
|
143
|
+
email:
|
106
144
|
- mkb@engineyard.com
|
107
145
|
executables: []
|
108
|
-
|
109
146
|
extensions: []
|
110
|
-
|
111
147
|
extra_rdoc_files: []
|
112
|
-
|
113
|
-
files:
|
148
|
+
files:
|
114
149
|
- .gitignore
|
150
|
+
- .travis.yml
|
115
151
|
- Gemfile
|
116
152
|
- Guardfile
|
117
153
|
- LICENSE
|
@@ -128,38 +164,30 @@ files:
|
|
128
164
|
- spec/support/database.yml
|
129
165
|
homepage: https://github.com/mkb/riak-shim
|
130
166
|
licenses: []
|
131
|
-
|
132
167
|
post_install_message:
|
133
168
|
rdoc_options: []
|
134
|
-
|
135
|
-
require_paths:
|
169
|
+
require_paths:
|
136
170
|
- lib
|
137
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
172
|
none: false
|
139
|
-
requirements:
|
140
|
-
- -
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
|
143
|
-
|
144
|
-
- 0
|
145
|
-
version: "0"
|
146
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
178
|
none: false
|
148
|
-
requirements:
|
149
|
-
- -
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
|
152
|
-
segments:
|
153
|
-
- 0
|
154
|
-
version: "0"
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
155
183
|
requirements: []
|
156
|
-
|
157
184
|
rubyforge_project:
|
158
185
|
rubygems_version: 1.8.24
|
159
186
|
signing_key:
|
160
187
|
specification_version: 3
|
161
|
-
summary: A tiny shim between you and riak-client. Reads config/database.yml and generates
|
162
|
-
|
188
|
+
summary: A tiny shim between you and riak-client. Reads config/database.yml and generates
|
189
|
+
sensible bucket names.
|
190
|
+
test_files:
|
163
191
|
- spec/persistable_spec.rb
|
164
192
|
- spec/spec_helper.rb
|
165
193
|
- spec/store_spec.rb
|