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 CHANGED
@@ -2,17 +2,10 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
- .yardoc
5
+ .rspec
6
6
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
7
  coverage
10
- doc/
11
- lib/bundler/man
12
8
  pkg
13
- rdoc
14
9
  spec/reports
15
- test/tmp
16
- test/version_tmp
17
10
  tmp
18
11
  vendor/bundle
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ script: bundle exec rspec spec
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
- development: &default
28
- bucket_prefix: dev_
29
- host: localhost
30
- http_port: 8098
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
- test:
33
- <<: *default
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
- In any class you wish to persist:
37
- include Riak::Shim::Persistable
49
+ def to_hash
50
+ # Return hashified version of your class
51
+ end
38
52
 
39
- def to_hash
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
- def self.from_hash(key)
44
- # Return a fresh instance of your class populated by the hash provided
45
- end
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
- def fields_to_index
48
- # Return an Array of hash keys you would like placed into a secondary index.
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
- Now you can save instances of that class by calling #save on them and retrieve them from Riak by calling
65
+ YourClass.for_key(key)
53
66
 
54
- YourClass.for_index(index_name, value)
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 = de_cammel(self.to_s)
52
+ myclass = de_camel(self.to_s)
54
53
  "#{store.bucket_prefix}#{myclass}"
55
54
  end
56
55
 
57
- def de_cammel(classname)
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
- from_hash(key)
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
@@ -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
- attr_reader :riak
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
@@ -1,5 +1,5 @@
1
1
  module Riak
2
2
  module Shim
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
data/lib/riak-shim.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "riak-shim/version"
2
2
  require "riak-shim/persistable"
3
3
  require "riak-shim/store"
4
- require "riak-shim/core_ext"
5
4
 
6
5
  module Riak
7
6
  module Shim
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 & Shai Rosenfeld"]
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 names and config.}
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.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
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
- hash: 23
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 & Shai Rosenfeld
7
+ authors:
8
+ - Michael Brodhead, Shai Rosenfeld, and Larry Diehl
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-07-12 00:00:00 Z
19
- dependencies:
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
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
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
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
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
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
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
- requirement: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
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
- requirement: &id005 !ruby/object:Gem::Requirement
80
- none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
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
- version_requirements: *id005
90
- - !ruby/object:Gem::Dependency
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
- requirement: &id006 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
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
- version_requirements: *id006
104
- description: Riak shim for bucket names and config.
105
- email:
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
- hash: 3
143
- segments:
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
- hash: 3
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 sensible bucket names.
162
- test_files:
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