relaxo-model 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaxo/model/base.rb +2 -0
- data/lib/relaxo/model/document.rb +15 -0
- data/lib/relaxo/model/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b93dd6c667e6ccb72426324f24cb514cc5a7e7dd
|
4
|
+
data.tar.gz: 260d2efe407173af153b6967a182595ccc446b07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7904176c5661e8dd32aafd89682b577c5a34a7ed17edca4376de70484ad27f4a89e3a3ee5f85f7c3ae4452ae40b3d5c7906887d08d26789557c192ba7a74be3f
|
7
|
+
data.tar.gz: b12df76b9ddb645a568ebcd88d2e0aa38d6fb5e13c2c07fdf1c31a2236961ae8ebe564930d860c6260321c351ac706d37dec5415532af482d3d0112ea439ad03
|
data/lib/relaxo/model/base.rb
CHANGED
@@ -34,6 +34,16 @@ module Relaxo
|
|
34
34
|
attr :errors
|
35
35
|
end
|
36
36
|
|
37
|
+
class TypeError < StandardError
|
38
|
+
def initialize(document)
|
39
|
+
@document = document
|
40
|
+
|
41
|
+
super "Expected type #{@document.class.type} but got #{@document.type}!"
|
42
|
+
end
|
43
|
+
|
44
|
+
attr :document
|
45
|
+
end
|
46
|
+
|
37
47
|
module Document
|
38
48
|
TYPE = 'type'
|
39
49
|
|
@@ -94,6 +104,10 @@ module Relaxo
|
|
94
104
|
@attributes[TYPE]
|
95
105
|
end
|
96
106
|
|
107
|
+
def valid_type?
|
108
|
+
self.type == @@type
|
109
|
+
end
|
110
|
+
|
97
111
|
# Update any calculations:
|
98
112
|
def before_save
|
99
113
|
end
|
@@ -154,6 +168,7 @@ module Relaxo
|
|
154
168
|
end
|
155
169
|
|
156
170
|
def after_fetch
|
171
|
+
raise TypeError.new(self) unless valid_type?
|
157
172
|
end
|
158
173
|
|
159
174
|
# Set any default values:
|
data/lib/relaxo/model/version.rb
CHANGED