remodel 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/remodel/entity.rb +14 -9
- data/test/test_entity.rb +6 -0
- data/test/test_inheritance.rb +4 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/remodel/entity.rb
CHANGED
@@ -77,6 +77,7 @@ module Remodel
|
|
77
77
|
|
78
78
|
def self.set_key_prefix(prefix)
|
79
79
|
raise(InvalidKeyPrefix, prefix) unless prefix =~ /^[a-z]+$/
|
80
|
+
raise(InvalidUse, "can only set key prefix for direct subclasses of entity") unless superclass == Entity
|
80
81
|
@key_prefix = prefix
|
81
82
|
end
|
82
83
|
|
@@ -151,11 +152,6 @@ module Remodel
|
|
151
152
|
"#{self.class.key_prefix}#{id}"
|
152
153
|
end
|
153
154
|
|
154
|
-
# Default key prefix is the first letter of the class name, in lowercase.
|
155
|
-
def self.key_prefix
|
156
|
-
@key_prefix ||= name.split('::').last[0,1].downcase
|
157
|
-
end
|
158
|
-
|
159
155
|
def self.parse(json)
|
160
156
|
unpack(JSON.parse(json))
|
161
157
|
end
|
@@ -194,8 +190,17 @@ module Remodel
|
|
194
190
|
# class instance variables:
|
195
191
|
# lazy init + recursive lookup in superclasses
|
196
192
|
|
193
|
+
def self.key_prefix
|
194
|
+
superclass == Entity ? _key_prefix : superclass.key_prefix
|
195
|
+
end
|
196
|
+
|
197
|
+
# Default key prefix is the first letter of the class name, in lowercase.
|
198
|
+
def self._key_prefix
|
199
|
+
@key_prefix ||= name.split('::').last[0,1].downcase
|
200
|
+
end
|
201
|
+
|
197
202
|
def self.mapper
|
198
|
-
|
203
|
+
superclass == Entity ? _mapper : superclass.mapper.merge(_mapper)
|
199
204
|
end
|
200
205
|
|
201
206
|
def self._mapper
|
@@ -203,7 +208,7 @@ module Remodel
|
|
203
208
|
end
|
204
209
|
|
205
210
|
def self.shortname
|
206
|
-
|
211
|
+
superclass == Entity ? _shortname : superclass.shortname.merge(_shortname)
|
207
212
|
end
|
208
213
|
|
209
214
|
def self._shortname
|
@@ -211,7 +216,7 @@ module Remodel
|
|
211
216
|
end
|
212
217
|
|
213
218
|
def self.fullname
|
214
|
-
|
219
|
+
superclass == Entity ? _fullname : superclass.fullname.merge(_fullname)
|
215
220
|
end
|
216
221
|
|
217
222
|
def self._fullname
|
@@ -219,7 +224,7 @@ module Remodel
|
|
219
224
|
end
|
220
225
|
|
221
226
|
def self.associations
|
222
|
-
|
227
|
+
superclass == Entity ? _associations : superclass.associations + _associations
|
223
228
|
end
|
224
229
|
|
225
230
|
def self._associations
|
data/test/test_entity.rb
CHANGED
@@ -188,6 +188,12 @@ class TestEntity < Test::Unit::TestCase
|
|
188
188
|
class InvalidPrefix < Remodel::Entity; set_key_prefix '666'; end
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
should "ensure that the class is a direct subclass of entity" do
|
193
|
+
assert_raise(Remodel::InvalidUse) do
|
194
|
+
class InvalidSetPrefix < Foo; set_key_prefix 'x'; end
|
195
|
+
end
|
196
|
+
end
|
191
197
|
end
|
192
198
|
|
193
199
|
context "#find" do
|
data/test/test_inheritance.rb
CHANGED