riak-record 0.2.0 → 0.3.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: e51ff6ee221ebec773b72a371ad33d36b67bfd00
4
- data.tar.gz: 5981fda818b55246e37830a9460c5efe12e66a63
3
+ metadata.gz: 323433e9c9fb5acd1f53b15aebadb059e8cd2302
4
+ data.tar.gz: f085f0f28796d53fb8e9146ab799ac54b55c86b8
5
5
  SHA512:
6
- metadata.gz: c7261d2c6f4abd75fc86475d3ed9b5b23232478dae3bd98d206e52615e315665e2fc9fffd71e645f1b1ae86f33caab532ac14fb9706cf9debd3aa209583953ee
7
- data.tar.gz: 758c83cdd23fb36cc4a0f1ab39db09efcd8ddf17698c2a0b771c8a3e9696e3f635d6fdca2533c1d53591a590c5415a132c50324567bedf81ffb2017c74de64bd
6
+ metadata.gz: 2fa5ac5afafbd7e089ab4d04ae8c7a1e4b7862cde0312b738aaca34b12a328904192adef314b7873754813d117e1ab9fffda3e4e5d77ed734204f34e48bcb147
7
+ data.tar.gz: 9ff0f2298cfd033786ee6f5b42fb8dc5a16224d6882b1339d13e54827cecefaf80eb6a5e62651b69a820c04e5b6df4a4aab86f3bfbfabbeb1dd9df1360af556d
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
- # riak-record
1
+ # RiakRecord
2
2
 
3
3
  RiakRecord is a thin and immature wrapper around riak-ruby-client. It creates a bucket for
4
- each class, provides a simple finder, and creates attribute reader. It adds a layer over
4
+ each class, provides a simple finder, and creates attribute accessors for data and indexes. It adds a layer over
5
5
  the Riak::Client to make interacting with Riak more ActiveRecord-like while
6
6
  still giving you all the access to Riak's underlying client's capabilities.
7
7
 
8
+ RiakRecord is is very similar to [Basho's Ripple](https://github.com/basho-labs/ripple) which is more feature rich
9
+ but also abandoned. For the [same reasons](http://basho.com/tag/ripple-client-apis/)
10
+ that Basho abandoned Ripple, you should think twice before using RiakRecord.
11
+
8
12
  ## Usage
9
13
 
10
14
  ```ruby
11
- require 'riak-record'
15
+ require 'riak_record'
12
16
 
13
17
  RiakRecord::Base.client = Riak::Client.new
14
18
  RiakRecord::Base.namespace = 'staging' # optional. Namespaces buckets
data/TODO.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  * RiakRecord::Base
4
4
  * links_to should create a walkable link
5
- * delete
6
- * new(hash)
7
5
  * id_generator
8
6
  * Document methods in classes
9
7
  * Validations support
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -10,13 +10,21 @@ module RiakRecord
10
10
  alias :belongs_to :belongs_to_riak
11
11
  end
12
12
 
13
- def initialize(r = nil)
14
- unless r.is_a? Riak::RObject
15
- r = self.class.bucket.new(r.to_s)
16
- r.data = {}
17
- r.content_type = 'application/json'
13
+ def initialize(options = nil)
14
+ if options.is_a?(Riak::RObject)
15
+ @riak_object = options
16
+ else
17
+ @riak_object = self.class.bucket.new
18
+ @riak_object.content_type = 'application/json'
19
+ @riak_object.data = {}
20
+ if options.is_a?(Hash)
21
+ id = options.delete(:id) || options.delete(:key)
22
+ @riak_object.key = id.to_s if id
23
+ options.each_pair{ |k,v| self.send("#{k}=".to_sym, v) }
24
+ elsif !options.nil?
25
+ @riak_object.key = options.to_s
26
+ end
18
27
  end
19
- @riak_object = r
20
28
  end
21
29
 
22
30
  def data
@@ -39,6 +47,19 @@ module RiakRecord
39
47
  @_stored = true
40
48
  self
41
49
  end
50
+ alias :save! :save
51
+
52
+ def self.create(*args)
53
+ self.new(*args).save
54
+ end
55
+
56
+ def self.create!(*args)
57
+ self.new(*args).save
58
+ end
59
+
60
+ def delete
61
+ riak_object.delete
62
+ end
42
63
 
43
64
  def new_record?
44
65
  !(@_stored || riak_object.vclock)
@@ -48,6 +69,11 @@ module RiakRecord
48
69
  riak_object.key
49
70
  end
50
71
 
72
+ def ==(record)
73
+ return false unless record.kind_of?(RiakRecord::Base)
74
+ self.class.bucket_name == record.class.bucket_name && id == record.id
75
+ end
76
+
51
77
  def reload
52
78
  @riak_object = self.class.bucket.get(id)
53
79
  @riak_object.data = {} if @riak_object.data.nil?
@@ -24,7 +24,11 @@ module RiakRecord
24
24
  end
25
25
  @loaded_objects
26
26
  end
27
- alias :to_a :all
27
+ alias :to_ary :all # internal array
28
+
29
+ def to_a
30
+ all.dup # new array
31
+ end
28
32
 
29
33
  def each
30
34
  all.each{|o| yield o}
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.2.0 ruby lib
5
+ # stub: riak-record 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "riak-record"
9
- s.version = "0.2.0"
9
+ s.version = "0.3.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-09-25"
14
+ s.date = "2014-09-26"
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 = [
@@ -25,6 +25,28 @@ describe RiakRecord::Base do
25
25
  expect(ExampleA.client).to eq(ExampleB.client)
26
26
  end
27
27
 
28
+ describe "new" do
29
+ it "should accept a string" do
30
+ record = ExampleA.new("abc")
31
+ expect(record.id).to eq("abc")
32
+ end
33
+ it "should accept a int" do
34
+ record = ExampleA.new(123)
35
+ expect(record.id).to eq("123")
36
+ end
37
+ it "should accept an robject" do
38
+ robject = ExampleA.bucket.new("abc")
39
+ record = ExampleA.new(robject)
40
+ expect(record.id).to eq("abc")
41
+ end
42
+ it "should accept a hash" do
43
+ record = ExampleA.new(:id => "abc", :attribute1 => 'sappy', :index1 => 123)
44
+ expect(record.id).to eq("abc")
45
+ expect(record.attribute1).to eq('sappy')
46
+ expect(record.index1).to eq([123])
47
+ end
48
+ end
49
+
28
50
  describe "index_names" do
29
51
  it "should look up the index by symbol" do
30
52
  expect( ExampleA.index_names[:index1] ).to eq("index1_int")
@@ -129,6 +151,15 @@ describe RiakRecord::Base do
129
151
  record.save
130
152
  end
131
153
  end
154
+
155
+ describe "delete" do
156
+ let(:saved_record){ ExampleA.create("abc") }
157
+ it "should remove from riak" do
158
+ expect{
159
+ saved_record.delete
160
+ }.to change{ ExampleA.find("abc") }.from(saved_record).to(nil)
161
+ end
162
+ end
132
163
  end
133
164
 
134
165
  describe "class methods" do
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.2.0
4
+ version: 0.3.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-09-25 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riak-client