zermelo 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/README.md +13 -13
- data/lib/zermelo/associations/has_one.rb +1 -1
- data/lib/zermelo/records/errors.rb +24 -5
- data/lib/zermelo/records/instance_methods.rb +12 -2
- data/lib/zermelo/version.rb +1 -1
- data/spec/lib/zermelo/records/redis_record_spec.rb +28 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7492dc2e67e9921a87e1dbea33eb721464dce5f
|
4
|
+
data.tar.gz: 62906c88696b9eb2fdfb8d2a94d0244184cd33da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dde70cf8e7c241eeef5de1925a67719a6c3779cc7afc784ffdca13e5925a146e8b8cb1797b4f70eb1c377a990057a1f2a008f94156201c81bcf705f999c61f27
|
7
|
+
data.tar.gz: 62fe986cbc4ab69699bfc2286ef58c17b8fa12c4e79c0c11a2d82ce805637c7f66a002a94b3e785bb4cb7d34fc1ffe74a7ce6f47c1d7ffb8ed8b82f56e34de58
|
data/.travis.yml
CHANGED
@@ -11,7 +11,7 @@ before_install:
|
|
11
11
|
- wget http://s3.amazonaws.com/influxdb/influxdb_0.8.8_amd64.deb
|
12
12
|
- sudo dpkg -i influxdb_0.8.8_amd64.deb
|
13
13
|
- sudo /etc/init.d/influxdb start
|
14
|
-
- sleep
|
14
|
+
- sleep 8
|
15
15
|
- 'curl -X POST ''http://localhost:8086/db?u=root&p=root'' -d ''{"name": "zermelo_test"}'''
|
16
16
|
- 'curl -X POST ''http://localhost:8086/db/zermelo_test/users?u=root&p=root'' -d
|
17
17
|
''{"name": "zermelo", "password": "zermelo"}'''
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -42,7 +42,7 @@ Include **zermelo**'s Record module in the class you want to persist data from:
|
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
class Post
|
45
|
-
include Zermelo
|
45
|
+
include Zermelo::Record
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
@@ -67,7 +67,7 @@ A data record without any actual data isn't very useful, so let's add a few simp
|
|
67
67
|
|
68
68
|
```ruby
|
69
69
|
class Post
|
70
|
-
include Zermelo
|
70
|
+
include Zermelo::Record
|
71
71
|
define_attributes :title => :string,
|
72
72
|
:score => :integer,
|
73
73
|
:timestamp => :timestamp,
|
@@ -116,7 +116,7 @@ So if we add tags to the Post data definition:
|
|
116
116
|
|
117
117
|
```ruby
|
118
118
|
class Post
|
119
|
-
include Zermelo
|
119
|
+
include Zermelo::Record
|
120
120
|
define_attributes :title => :string,
|
121
121
|
:score => :integer,
|
122
122
|
:timestamp => :timestamp,
|
@@ -161,7 +161,7 @@ So an attribute which should be present:
|
|
161
161
|
|
162
162
|
```ruby
|
163
163
|
class Post
|
164
|
-
include Zermelo
|
164
|
+
include Zermelo::Record
|
165
165
|
define_attributes :title => :string,
|
166
166
|
:score => :integer
|
167
167
|
validates :title, :presence => true
|
@@ -202,15 +202,15 @@ Another feature added by ActiveModel is the ability to detect changed data in re
|
|
202
202
|
|
203
203
|
```ruby
|
204
204
|
class Author
|
205
|
-
include Zermelo
|
205
|
+
include Zermelo::Record
|
206
206
|
end
|
207
207
|
|
208
208
|
class Post
|
209
|
-
include Zermelo
|
209
|
+
include Zermelo::Record
|
210
210
|
end
|
211
211
|
|
212
212
|
class Comment
|
213
|
-
include Zermelo
|
213
|
+
include Zermelo::Record
|
214
214
|
end
|
215
215
|
|
216
216
|
Author.lock(Post, Comment) do
|
@@ -224,7 +224,7 @@ Assuming a saved `Post` instance has been created:
|
|
224
224
|
|
225
225
|
```ruby
|
226
226
|
class Post
|
227
|
-
include Zermelo
|
227
|
+
include Zermelo::Record
|
228
228
|
define_attributes :title => :string,
|
229
229
|
:score => :integer,
|
230
230
|
:timestamp => :timestamp,
|
@@ -303,12 +303,12 @@ Instances also have attribute accessors and the various methods included from th
|
|
303
303
|
|
304
304
|
```ruby
|
305
305
|
class Post
|
306
|
-
include Zermelo
|
306
|
+
include Zermelo::Record
|
307
307
|
has_many :comments, :class_name => 'Comment', :inverse_of => :post
|
308
308
|
end
|
309
309
|
|
310
310
|
class Comment
|
311
|
-
include Zermelo
|
311
|
+
include Zermelo::Record
|
312
312
|
belongs_to :post, :class_name => 'Post', :inverse_of => :comments
|
313
313
|
end
|
314
314
|
```
|
@@ -331,12 +331,12 @@ post.comments.add(comment1, comment2, comment3)
|
|
331
331
|
|
332
332
|
```ruby
|
333
333
|
class User
|
334
|
-
include Zermelo
|
334
|
+
include Zermelo::Record
|
335
335
|
has_one :preferences, :class_name => 'Preferences', :inverse_of => :user
|
336
336
|
end
|
337
337
|
|
338
338
|
class Preferences
|
339
|
-
include Zermelo
|
339
|
+
include Zermelo::Record
|
340
340
|
belongs_to :user, :class_name => 'User', :inverse_of => :preferences
|
341
341
|
end
|
342
342
|
|
@@ -398,7 +398,7 @@ Using the code from the instance attributes section, and adding indexing:
|
|
398
398
|
|
399
399
|
```ruby
|
400
400
|
class Post
|
401
|
-
include Zermelo
|
401
|
+
include Zermelo::Record
|
402
402
|
define_attributes :title => :string,
|
403
403
|
:score => :integer,
|
404
404
|
:timestamp => :timestamp,
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module Zermelo
|
2
|
+
|
3
|
+
class ZermeloError < RuntimeError
|
4
|
+
end
|
5
|
+
|
2
6
|
module Records
|
3
7
|
module Errors
|
4
|
-
|
5
|
-
class RecordNotFound < RuntimeError
|
8
|
+
class RecordNotFound < ::Zermelo::ZermeloError
|
6
9
|
attr_reader :klass, :id
|
7
10
|
|
8
11
|
def initialize(k, i)
|
@@ -11,7 +14,7 @@ module Zermelo
|
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
|
-
class RecordsNotFound <
|
17
|
+
class RecordsNotFound < ::Zermelo::ZermeloError
|
15
18
|
attr_reader :klass, :ids
|
16
19
|
|
17
20
|
def initialize(k, i)
|
@@ -19,6 +22,22 @@ module Zermelo
|
|
19
22
|
@ids = i
|
20
23
|
end
|
21
24
|
end
|
22
|
-
|
23
|
-
|
25
|
+
|
26
|
+
class RecordInvalid < ::Zermelo::ZermeloError
|
27
|
+
attr_reader :record
|
28
|
+
|
29
|
+
def initialize(r)
|
30
|
+
@record = r
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class RecordNotSaved < ::Zermelo::ZermeloError
|
35
|
+
attr_reader :record
|
36
|
+
|
37
|
+
def initialize(r)
|
38
|
+
@record = r
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
24
43
|
end
|
@@ -74,12 +74,13 @@ module Zermelo
|
|
74
74
|
save
|
75
75
|
end
|
76
76
|
|
77
|
-
def save
|
77
|
+
def save!
|
78
78
|
return unless @is_new || self.changed?
|
79
79
|
self.id ||= self.class.generate_id
|
80
|
-
|
80
|
+
raise Zermelo::Records::Errors::RecordInvalid.new(self) unless valid?
|
81
81
|
|
82
82
|
creating = !self.persisted?
|
83
|
+
saved = false
|
83
84
|
|
84
85
|
run_callbacks( (creating ? :create : :update) ) do
|
85
86
|
|
@@ -123,8 +124,11 @@ module Zermelo
|
|
123
124
|
end
|
124
125
|
|
125
126
|
@is_new = false
|
127
|
+
saved = true
|
126
128
|
end
|
127
129
|
|
130
|
+
raise Zermelo::Records::Errors::RecordNotSaved.new(self) unless saved
|
131
|
+
|
128
132
|
# AM::Dirty -- private method in 4.1.0+, internal state before that
|
129
133
|
if self.respond_to?(:changes_applied, true)
|
130
134
|
changes_applied
|
@@ -136,6 +140,12 @@ module Zermelo
|
|
136
140
|
true
|
137
141
|
end
|
138
142
|
|
143
|
+
def save
|
144
|
+
save!
|
145
|
+
rescue Zermelo::Records::Errors::RecordInvalid, Zermelo::Records::Errors::RecordNotSaved
|
146
|
+
false
|
147
|
+
end
|
148
|
+
|
139
149
|
def destroy
|
140
150
|
raise "Record was not persisted" if !persisted?
|
141
151
|
|
data/lib/zermelo/version.rb
CHANGED
@@ -32,6 +32,18 @@ describe Zermelo::Records::RedisRecord, :redis => true do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
class RedisUnsavable
|
36
|
+
include Zermelo::Records::RedisRecord
|
37
|
+
|
38
|
+
define_attributes :name => :string
|
39
|
+
|
40
|
+
before_create :block_create
|
41
|
+
|
42
|
+
def block_create
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
35
47
|
class RedisExampleChild
|
36
48
|
include Zermelo::Records::RedisRecord
|
37
49
|
|
@@ -111,6 +123,22 @@ describe Zermelo::Records::RedisRecord, :redis => true do
|
|
111
123
|
)
|
112
124
|
end
|
113
125
|
|
126
|
+
it 'raises an RecordInvalid exception if validation fails while saving' do
|
127
|
+
example = Zermelo::RedisExample.new(:id => '1', :email => 'jsmith@example.com')
|
128
|
+
|
129
|
+
expect {
|
130
|
+
example.save!
|
131
|
+
}.to raise_error(Zermelo::Records::Errors::RecordInvalid)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'raises a RecordNotSaved exception if a callback blocks saving' do
|
135
|
+
example = Zermelo::RedisUnsavable.new(:id => '1', :name => 'not saving')
|
136
|
+
|
137
|
+
expect {
|
138
|
+
example.save!
|
139
|
+
}.to raise_error(Zermelo::Records::Errors::RecordNotSaved)
|
140
|
+
end
|
141
|
+
|
114
142
|
it "finds a record by id in redis" do
|
115
143
|
create_example(:id => '8', :name => 'John Jones',
|
116
144
|
:email => 'jjones@example.com', :active => 'true')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zermelo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ali Graham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|