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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 349ba7bffa4ad94b6ebcfffe6e7bfe552d307923
4
- data.tar.gz: 628a83cbfd02d07016f0701eb917ecee4fda2950
3
+ metadata.gz: b93dd6c667e6ccb72426324f24cb514cc5a7e7dd
4
+ data.tar.gz: 260d2efe407173af153b6967a182595ccc446b07
5
5
  SHA512:
6
- metadata.gz: 16aa6fb5ec9777433984c1f7ec166293596e41177aaca36f847a6d7e2b75cb0594af7a27d4ac1bfb9b8f92f7dc498311f3033b0a670ff2fa9e8e4e7f02b219f4
7
- data.tar.gz: 9567deabd3238d84ce9c6d91708a59cd9030dc91032ee5aa80cc52ed7f2f5ece17e72c66e94a4b77992ffdd4d27c7b4c13d2c64123bcab0c5340a1fd3d3fb3c5
6
+ metadata.gz: 7904176c5661e8dd32aafd89682b577c5a34a7ed17edca4376de70484ad27f4a89e3a3ee5f85f7c3ae4452ae40b3d5c7906887d08d26789557c192ba7a74be3f
7
+ data.tar.gz: b12df76b9ddb645a568ebcd88d2e0aa38d6fb5e13c2c07fdf1c31a2236961ae8ebe564930d860c6260321c351ac706d37dec5415532af482d3d0112ea439ad03
@@ -32,6 +32,8 @@ module Relaxo
32
32
  child.instance_variable_set(:@type, default_type)
33
33
  end
34
34
 
35
+ attr :type
36
+
35
37
  def metaclass
36
38
  class << self; self; end
37
39
  end
@@ -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:
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module Model
23
- VERSION = "0.4.9"
23
+ VERSION = "0.4.10"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams