riak-record 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/TODO.md +2 -0
- data/VERSION +1 -1
- data/lib/riak_record/finder.rb +19 -22
- data/riak-record.gemspec +3 -3
- data/spec/riak_record/finder_spec.rb +20 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2627d29a43209e31719b15501c12d2f272fc6d0
|
4
|
+
data.tar.gz: 3821d3333a91374965a04717b18e93b9b6f5d3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4346ef7b3b5869b5ad73d24be6b6b7c15f37ea46a7fcfd8dce89f95ee4baeaf8a9aa83d23916636dccb98694a0a9131b9617d0d3ff6dcd209817020ca9b68062
|
7
|
+
data.tar.gz: 6ede597c3201ea403b23fff5c0d3074eecb013a3827dc188714cd2d63347eab8cfca5a741d3ca4b6f0c8d368063aa10d23e5da7dd91e1602a108388653935972
|
data/README.md
CHANGED
@@ -29,7 +29,9 @@ Post.client #> instance of Riak::Client
|
|
29
29
|
Post.bucket #> instance of Riak::Bucket named "staging:posts"
|
30
30
|
Post.all #> [] uses the special $bucket secondary index
|
31
31
|
Post.count #> 0 also uses the special $bucket index
|
32
|
-
|
32
|
+
|
33
|
+
records, continuation_token = Post.page() #> returns records 1-100 using the $bucket index.
|
34
|
+
records2, continuation_token = Post.page(continuation_token) #> returns records 101-200
|
33
35
|
|
34
36
|
Post.find(["my-first-post","a-farewell-to-blogging"]) #> Array of Posts returned
|
35
37
|
post = Post.find("my-first-post") #> Instance of Post
|
@@ -63,13 +65,20 @@ RiakRecord::Finder provides find objects by indexes. Results are loaded in batch
|
|
63
65
|
|
64
66
|
```ruby
|
65
67
|
finder = Post.where(:category => 'ruby') #> Instance of RiakRecord::Finder
|
66
|
-
finder.page(1) # returns the first 100 records. Note it has to stream in previous pages
|
67
68
|
finder.count #> 1
|
68
69
|
finder.any? #> true
|
69
70
|
finder.any?{|o| o.category == 'php'} #> false
|
70
71
|
finder.none? #> false
|
71
72
|
finder.each{|e| ... } #> supports all enumerable methods
|
72
|
-
finder.count_by(:author_id) #> {"1" => 1}
|
73
|
+
finder.count_by(:author_id) #> {"1" => 1}. Works with declared data attributes and indexes
|
74
|
+
finder.pluck(:author_id) #> [1,2,3]. Works with declared data attributes and indexes
|
75
|
+
```
|
76
|
+
|
77
|
+
#### Pagination
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
records, contination_token = finder.page() # returns the first 100 records.
|
81
|
+
records2, contination_token = finder.page(contination_token, 10) # returns records 101-10
|
73
82
|
```
|
74
83
|
|
75
84
|
### RiakRecord::Associations
|
data/TODO.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/riak_record/finder.rb
CHANGED
@@ -40,12 +40,12 @@ module RiakRecord
|
|
40
40
|
|
41
41
|
def first(n=nil)
|
42
42
|
if n
|
43
|
-
|
44
|
-
load_next_page
|
43
|
+
unless @load_complete || @loaded_objects.count >= n
|
44
|
+
load_next_page(n-@loaded_objects.count)
|
45
45
|
end
|
46
46
|
@loaded_objects.first(n)
|
47
47
|
else
|
48
|
-
load_next_page unless load_started?
|
48
|
+
load_next_page(1) unless load_started?
|
49
49
|
@loaded_objects.first
|
50
50
|
end
|
51
51
|
end
|
@@ -65,7 +65,7 @@ module RiakRecord
|
|
65
65
|
if block_given?
|
66
66
|
!any?(&block)
|
67
67
|
else
|
68
|
-
load_next_page unless load_started?
|
68
|
+
load_next_page(1) unless load_started?
|
69
69
|
@loaded_objects.count.zero?
|
70
70
|
end
|
71
71
|
end
|
@@ -90,23 +90,20 @@ module RiakRecord
|
|
90
90
|
results
|
91
91
|
end
|
92
92
|
|
93
|
-
def page(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
querier = Riak::SecondaryIndex.new(@bucket, @index, @value, :max_results => page_size)
|
99
|
-
while current_page < page_number
|
100
|
-
if querier.has_next_page?
|
101
|
-
querier = querier.next_page
|
102
|
-
current_page = current_page + 1
|
103
|
-
else
|
104
|
-
return [], false # no results, no next page
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
93
|
+
def page(continuation = nil, page_size = 100)
|
94
|
+
options = { :max_results => page_size }
|
95
|
+
options[:continuation] = continuation if continuation.present?
|
96
|
+
querier = Riak::SecondaryIndex.new(@bucket, @index, @value, options)
|
108
97
|
results = querier.values.compact.map{ |robject| @finder_class.new(robject) }
|
109
|
-
return results, querier.
|
98
|
+
return results, querier.keys.continuation
|
99
|
+
end
|
100
|
+
|
101
|
+
def pluck_by_map_reduce(attribute)
|
102
|
+
pluck_by_index = @finder_class.index_names[attribute.to_sym].present?
|
103
|
+
parsed_attribute = pluck_by_index ? "v.values[0].metadata.index.#{@finder_class.index_names[attribute.to_sym]}" : "JSON.parse(v.values[0].data).#{attribute}"
|
104
|
+
Riak::MapReduce.new(@finder_class.client).
|
105
|
+
index(@bucket, @index, @value).
|
106
|
+
map("function(v){ return [#{parsed_attribute}] }", :keep => true).run
|
110
107
|
end
|
111
108
|
|
112
109
|
private
|
@@ -131,12 +128,12 @@ module RiakRecord
|
|
131
128
|
reduce("Riak.reduceSum", :keep => true).run.first
|
132
129
|
end
|
133
130
|
|
134
|
-
def load_next_page
|
131
|
+
def load_next_page(page_size = @page_size)
|
135
132
|
return if @load_complete
|
136
133
|
if @querier
|
137
134
|
@querier = @querier.next_page
|
138
135
|
else
|
139
|
-
@querier = Riak::SecondaryIndex.new(@bucket, @index, @value, :max_results =>
|
136
|
+
@querier = Riak::SecondaryIndex.new(@bucket, @index, @value, :max_results => page_size)
|
140
137
|
end
|
141
138
|
@load_complete = !@querier.has_next_page?
|
142
139
|
new_objects = @querier.values.compact.map{ |robject| @finder_class.new(robject) }
|
data/riak-record.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: riak-record 0.
|
5
|
+
# stub: riak-record 0.6.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "riak-record"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.6.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Robert Graff"]
|
14
|
-
s.date = "2014-10-
|
14
|
+
s.date = "2014-10-22"
|
15
15
|
s.description = "RiakRecord is a thin and immature wrapper around riak-ruby-client. It creates a bucket for\n each class, provides a simple finder, and creates attribute reader."
|
16
16
|
s.email = "robert_graff@yahoo.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -64,21 +64,23 @@ describe RiakRecord::Finder do
|
|
64
64
|
|
65
65
|
describe "page" do
|
66
66
|
it "should return a page of results" do
|
67
|
-
results,
|
67
|
+
results, continuation = pop_finder.page(nil,10)
|
68
68
|
expect(results.map(&:id).sort).to eq(pop_finder.first(10).map(&:id).sort)
|
69
|
-
expect(
|
69
|
+
expect(continuation).to be_present
|
70
70
|
end
|
71
71
|
|
72
|
-
it "should return
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
it "should return the next page with a contination" do
|
73
|
+
results1, continuation1 = pop_finder.page(nil,10)
|
74
|
+
results, continuation = pop_finder.page(continuation1,10)
|
75
|
+
|
76
|
+
expect(results.map(&:id).sort).to eq(pop_finder.to_a.slice(10,10).map(&:id).sort)
|
77
|
+
expect(continuation).to be_present
|
76
78
|
end
|
77
79
|
|
78
80
|
it "should return results and false on last page" do
|
79
|
-
results,
|
81
|
+
results, continuation = pop_finder.page(nil, 500)
|
80
82
|
expect(results).to_not be_empty
|
81
|
-
expect(
|
83
|
+
expect(continuation).to_not be_present
|
82
84
|
end
|
83
85
|
|
84
86
|
end
|
@@ -148,6 +150,16 @@ describe RiakRecord::Finder do
|
|
148
150
|
end
|
149
151
|
end
|
150
152
|
|
153
|
+
describe "pluck_by_map_reduce(attribute)" do
|
154
|
+
it "should just return the plucked attributes" do
|
155
|
+
expect(pop_finder.pluck_by_map_reduce(:name).sort).to eq(@pop_artists.map(&:name).sort)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should pluck indexes too" do
|
159
|
+
expect(pop_finder.pluck_by_map_reduce(:sales).sort).to eq(@pop_artists.map(&:sales).map(&:first).sort)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
151
163
|
describe "count_by(attribute)" do
|
152
164
|
let(:bin_number_counts){
|
153
165
|
{ "0" => 15, "1" => 16, "2" => 16, "3" => 16, "4" => 16, "5" => 16, "6" => 15, "7" => 15, "8" => 15, "9" => 15}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riak-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Graff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: riak-client
|