ork 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ork/errors.rb +3 -1
- data/lib/ork/model.rb +11 -0
- data/lib/ork/model/associations.rb +21 -8
- data/ork.gemspec +1 -1
- 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: 2c07bdc3fa0fd2f3ed00a327a9ca745315e33243
|
4
|
+
data.tar.gz: 9059ca0b44c7d24afdec3db8ce3ad8a2de5b05be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8da194455a375e7e84f75bbec0776ef9e5b5bcfa068b36eb7a27528b9bea1263a220a2ac3826921e94f22eea7e163469b87fb8e4b9cb705d050569d3fb72bcd8
|
7
|
+
data.tar.gz: d5e4c535d1f791a17994af104700173dcc5cd58ebc5968088931628e98fa15dbf826234987ba9294cc7d89e46754cb957a4710aaac83c41a40f9a2895341a22d
|
data/lib/ork/errors.rb
CHANGED
@@ -3,11 +3,13 @@ module Ork
|
|
3
3
|
class IndexNotFound < RuntimeError; end
|
4
4
|
class UniqueIndexViolation < RuntimeError; end
|
5
5
|
|
6
|
+
class NotOrkObject < StandardError; end
|
7
|
+
|
6
8
|
# Document
|
7
9
|
class InvalidClass < RuntimeError; end
|
8
10
|
|
9
11
|
# Embedded
|
10
|
-
class
|
12
|
+
class NotEmbeddable < StandardError; end
|
11
13
|
class ParentMissing < RuntimeError; end
|
12
14
|
|
13
15
|
|
data/lib/ork/model.rb
CHANGED
@@ -68,5 +68,16 @@ module Ork
|
|
68
68
|
|
69
69
|
model.new attributes
|
70
70
|
end
|
71
|
+
|
72
|
+
def assert_valid_class(object, model)
|
73
|
+
raise Ork::NotOrkObject.new(object) unless object.class.include? Ork::Document
|
74
|
+
raise Ork::InvalidClass.new(object) if object.class.name != model.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def assert_embeddable(object)
|
78
|
+
unless object.respond_to?(:embeddable?) && object.embeddable?
|
79
|
+
raise Ork::NotEmbeddable.new(object)
|
80
|
+
end
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
@@ -47,7 +47,8 @@ module Ork::Model
|
|
47
47
|
end
|
48
48
|
|
49
49
|
define_method(:"#{name}=") do |object|
|
50
|
-
|
50
|
+
assert_valid_class object, model
|
51
|
+
|
51
52
|
send(writer, object ? object.id : nil)
|
52
53
|
@_memo[name] = object
|
53
54
|
end
|
@@ -145,12 +146,18 @@ module Ork::Model
|
|
145
146
|
end
|
146
147
|
|
147
148
|
define_method(:"#{name}_add") do |object|
|
148
|
-
|
149
|
+
assert_valid_class object, model
|
149
150
|
|
150
151
|
@attributes[reader] = Array(@attributes[reader]) << object.id
|
151
|
-
@_memo[name] << object
|
152
|
+
@_memo[name] << object if @_memo[name]
|
152
153
|
end
|
153
154
|
|
155
|
+
define_method(:"#{name}_remove") do |object|
|
156
|
+
assert_valid_class object, model
|
157
|
+
|
158
|
+
@_memo[name].delete(object) if @_memo[name]
|
159
|
+
@attributes[reader].delete(object.id) and object if @attributes[reader]
|
160
|
+
end
|
154
161
|
end
|
155
162
|
|
156
163
|
# A macro for defining an attribute, and the accessors
|
@@ -191,9 +198,7 @@ module Ork::Model
|
|
191
198
|
end
|
192
199
|
|
193
200
|
define_method(:"#{name}=") do |object|
|
194
|
-
|
195
|
-
raise Ork::NotAnEmbeddableObject.new(object)
|
196
|
-
end
|
201
|
+
assert_embeddable object
|
197
202
|
|
198
203
|
@embedding[name] = object.attributes
|
199
204
|
object.__parent = self
|
@@ -242,12 +247,20 @@ module Ork::Model
|
|
242
247
|
end
|
243
248
|
|
244
249
|
define_method(:"#{name}_add") do |object|
|
245
|
-
|
250
|
+
assert_embeddable object
|
246
251
|
|
247
252
|
object.__parent = self
|
248
|
-
@_memo[name] << object
|
253
|
+
@_memo[name] << object if @_memo[name]
|
249
254
|
@embedding[name] = Array(@embedding[name]) << object.attributes
|
250
255
|
end
|
256
|
+
|
257
|
+
define_method(:"#{name}_remove") do |object|
|
258
|
+
assert_embeddable object
|
259
|
+
|
260
|
+
object.__parent = nil
|
261
|
+
@_memo[name].delete(object) if @_memo[name]
|
262
|
+
@embedding[name].delete(object.attributes) and object if @embedding[name]
|
263
|
+
end
|
251
264
|
end
|
252
265
|
|
253
266
|
private
|
data/ork.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emiliano Mancuso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: riak-client
|