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 CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -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
- self == Entity || superclass == Entity ? _mapper : superclass.mapper.merge(_mapper)
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
- self == Entity || superclass == Entity ? _shortname : superclass.shortname.merge(_shortname)
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
- self == Entity || superclass == Entity ? _fullname : superclass.fullname.merge(_fullname)
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
- self == Entity || superclass == Entity ? _associations : superclass.associations + _associations
227
+ superclass == Entity ? _associations : superclass.associations + _associations
223
228
  end
224
229
 
225
230
  def self._associations
@@ -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
@@ -60,6 +60,10 @@ class TestInheritance < Test::Unit::TestCase
60
60
  assert_match /"n":/, json
61
61
  assert_match /"p":/, json
62
62
  end
63
+
64
+ should "use the same prefix as the superclass" do
65
+ assert_equal 'p', Admin.key_prefix
66
+ end
63
67
  end
64
68
 
65
69
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Lossen