riak-record 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4634d0a8658d10c47899dd710c7952d6d129e1f2
4
- data.tar.gz: 51df5cf9ca86b4aa9aec46c8213111642b9f0d36
3
+ metadata.gz: 7ac4b19f9c1851d3ad91962afa2bf5feb098659b
4
+ data.tar.gz: 1f0f42bde745441a2e853749e6d1506b503a1487
5
5
  SHA512:
6
- metadata.gz: 32b6c185d2bcc27ff1fd6cebd9097d31df3a1cce646f66b80ea59066e338cec8437e6249750b235b16f888cb61fa3ccf400bccba213866e78d6cc24a925a0193
7
- data.tar.gz: 09cdc00d887a3c22fa6b8265f4f80bb03affea55a4f3b4a1059f3bf6d7975d7769e76c9ce8c8c2d1d85a64178fc691f1060919ed58a540614ce04624e69f96c9
6
+ metadata.gz: d2ddfc8567dde15c17386c2f2949f22f90c21c649773b9dfe554711ad3b151cd73dc1a058b45b3d203051ebbc4b5b745e6a84edc1be92dd794bd96fa4da21f14
7
+ data.tar.gz: 7005462108cdb4a7cca7a6e8639f8fbee34e60f147a85d93d1b062b70960993af8d57371f87ef33e23767baf90b0aea1e315b33843aeda62412a16aab31530b2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.8.0
@@ -128,6 +128,10 @@ module RiakRecord
128
128
  finder.count
129
129
  end
130
130
 
131
+ def self.keys
132
+ finder.keys
133
+ end
134
+
131
135
  def self.first(n = 1)
132
136
  finder.first(n)
133
137
  end
@@ -31,6 +31,10 @@ module Finder
31
31
  all.dup # new array
32
32
  end
33
33
 
34
+ def keys
35
+ @keys ||= Riak::SecondaryIndex.new(@bucket, @index, @value).keys
36
+ end
37
+
34
38
  def each
35
39
  all.each{|o| yield o}
36
40
  end
@@ -102,9 +106,7 @@ module Finder
102
106
  def pluck_by_map_reduce(attribute, timeout = nil)
103
107
  pluck_by_index = @finder_class.index_names[attribute.to_sym].present?
104
108
  parsed_attribute = pluck_by_index ? "v.values[0].metadata.index.#{@finder_class.index_names[attribute.to_sym]}" : "JSON.parse(v.values[0].data).#{attribute}"
105
- mr = Riak::MapReduce.new(@finder_class.client).
106
- index(@bucket, @index, @value).
107
- map("function(v){ return [#{parsed_attribute}] }", :keep => true)
109
+ mr = new_map_reduce.map("function(v){ return [#{parsed_attribute}] }", :keep => true)
108
110
  mr.timeout = timeout if timeout.present?
109
111
  mr.run
110
112
  end
@@ -112,22 +114,26 @@ module Finder
112
114
  def count_by_map_reduce(attribute, timeout = nil)
113
115
  count_by_index = @finder_class.index_names[attribute.to_sym].present?
114
116
  parsed_attribute = count_by_index ? "v.values[0].metadata.index.#{@finder_class.index_names[attribute.to_sym]}" : "JSON.parse(v.values[0].data).#{attribute}"
115
- Riak::MapReduce.new(@finder_class.client).
116
- index(@bucket, @index, @value).
117
- map("function(v){ var h = {}; h[#{parsed_attribute}] = 1; return [h] }", :keep => false).
118
- reduce("function(values) { var result = {}; for (var value in values) { for (var key in values[value]) { if (key in result) { result[key] += values[value][key]; } else { result[key] = values[value][key]; }}} return [result]; }", :keep => true).run.first
117
+ mr = new_map_reduce.map("function(v){ var h = {}; h[#{parsed_attribute}] = 1; return [h] }", :keep => false).
118
+ reduce("function(values) { var result = {}; for (var value in values) { for (var key in values[value]) { if (key in result) { result[key] += values[value][key]; } else { result[key] = values[value][key]; }}} return [result]; }", :keep => true)
119
+ mr.timeout = timeout if timeout.present?
120
+ mr.run.first
119
121
  end
120
122
 
121
123
  def count_map_reduce(timeout = nil)
122
- Riak::MapReduce.new(@finder_class.client).
123
- index(@bucket, @index, @value).
124
- map("function(v){ return [1] }", :keep => false).
125
- reduce(['riak_kv_mapreduce','reduce_sum'], :keep => true).run.first
124
+ mr = new_map_reduce.map("function(v){ return [1] }", :keep => false).
125
+ reduce(['riak_kv_mapreduce','reduce_sum'], :keep => true)
126
+ mr.timeout = timeout if timeout.present?
127
+ mr.run.first
126
128
  end
127
129
 
128
130
 
129
131
  private
130
132
 
133
+ def new_map_reduce
134
+ Riak::MapReduce.new(@finder_class.client).index(@bucket, @index, @value)
135
+ end
136
+
131
137
  def load_started?
132
138
  @load_complete || @loaded_objects.count > 0
133
139
  end
@@ -3,17 +3,14 @@ module RiakRecord
3
3
 
4
4
  def pluck_by_map_reduce(attribute, timeout = nil)
5
5
  map_method, map_arg = map_method_for_attribute(attribute, "map_pluck_index", "map_pluck_value")
6
- mr = Riak::MapReduce.new(@finder_class.client).
7
- index(@bucket, @index, @value).
8
- map(['riak_record_kv_mapreduce', map_method], :keep => true, :arg => [map_arg])
6
+ mr = new_map_reduce.map(['riak_record_kv_mapreduce', map_method], :keep => true, :arg => [map_arg])
9
7
  mr.timeout = timeout if timeout.present?
10
8
  mr.run
11
9
  end
12
10
 
13
11
  def count_by_map_reduce(attribute, timeout = nil)
14
12
  map_method, map_arg = map_method_for_attribute(attribute, "map_count_by_index", "map_count_by_value")
15
- mr = Riak::MapReduce.new(@finder_class.client).
16
- index(@bucket, @index, @value).
13
+ mr = new_map_reduce.
17
14
  map(['riak_record_kv_mapreduce', map_method], :keep => false, :arg => [map_arg]).
18
15
  reduce(['riak_record_kv_mapreduce', 'reduce_count_by'], :keep => true)
19
16
  mr.timeout = timeout if timeout.present?
@@ -21,8 +18,7 @@ module RiakRecord
21
18
  end
22
19
 
23
20
  def count_map_reduce(timeout = nil)
24
- mr = Riak::MapReduce.new(@finder_class.client).
25
- index(@bucket, @index, @value).
21
+ mr = new_map_reduce.
26
22
  map(['riak_record_kv_mapreduce', 'map_count_found'], :keep => false).
27
23
  reduce(['riak_kv_mapreduce','reduce_sum'], :keep => true)
28
24
  mr.timeout = timeout if timeout.present?
Binary file
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.7.2 ruby lib
5
+ # stub: riak-record 0.8.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "riak-record"
9
- s.version = "0.7.2"
9
+ s.version = "0.8.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-28"
14
+ s.date = "2014-10-29"
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 = [
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/riak_record/finder/basic.rb",
37
37
  "lib/riak_record/finder/erlang_enhanced.rb",
38
38
  "map_reduce/riak_record_kv_mapreduce.erl",
39
+ "riak-record-0.7.2.gem",
39
40
  "riak-record.gemspec",
40
41
  "spec/riak_record/associations_spec.rb",
41
42
  "spec/riak_record/base_spec.rb",
@@ -258,6 +258,12 @@ describe RiakRecord::Base do
258
258
  end
259
259
  end
260
260
 
261
+ describe "keys" do
262
+ it "should reutrn all the keys in the bucket" do
263
+ expect(ExampleB.keys).to include("1","2")
264
+ end
265
+ end
266
+
261
267
  describe "count" do
262
268
  it "should count all objects in the bucket" do
263
269
  sleep(2) # wait for riak to collect ghosts
@@ -40,12 +40,22 @@ RSpec.shared_examples "riak_record_finder" do
40
40
  expect( pop_finder.all.map(&:id).sort ).to eq(@pop_artists.map(&:id).sort)
41
41
  end
42
42
 
43
- it "should not return all the record that do not match the conditions" do
43
+ it "should not return all the records that do not match the conditions" do
44
44
  expect( pop_finder.all.map(&:id) ).to_not include(@rock_artists.map(&:id))
45
45
  end
46
46
 
47
47
  end
48
48
 
49
+ describe "keys" do
50
+ it "should return all the keys that match the conditions" do
51
+ expect( pop_finder.keys.sort ).to eq(@pop_artists.map(&:id).sort)
52
+ end
53
+
54
+ it "should not return all the keys that do not match the conditions" do
55
+ expect( pop_finder.keys ).to_not include(@rock_artists.map(&:id))
56
+ end
57
+ end
58
+
49
59
  describe "count" do
50
60
  it "should return the count by map reduce" do
51
61
  expect(pop_finder).to receive(:count_map_reduce).and_call_original
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.7.2
4
+ version: 0.8.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-28 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riak-client
@@ -163,6 +163,7 @@ files:
163
163
  - lib/riak_record/finder/basic.rb
164
164
  - lib/riak_record/finder/erlang_enhanced.rb
165
165
  - map_reduce/riak_record_kv_mapreduce.erl
166
+ - riak-record-0.7.2.gem
166
167
  - riak-record.gemspec
167
168
  - spec/riak_record/associations_spec.rb
168
169
  - spec/riak_record/base_spec.rb