bsm_models 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,8 +15,8 @@ module Bsm::Model::StiConvertable
15
15
  # @Override: Allow to specify a kind
16
16
  def new(attributes = nil, *args, &block)
17
17
  kind = (attributes = attributes.with_indifferent_access).delete(:kind) if attributes.is_a?(Hash)
18
- klass = real_descendants.find {|k| k.kind == kind }
19
- return super unless klass
18
+ klass = real_descendants.find {|k| k.kind == kind } || fallback_descendant
19
+ return super if klass == self
20
20
 
21
21
  klass.with_scope(respond_to?(:current_scope) ? current_scope : current_scoped_methods) do # AR 3.0 compatibility
22
22
  klass.new(attributes, *args, &block)
@@ -27,6 +27,10 @@ module Bsm::Model::StiConvertable
27
27
  descendants.select(&:real_type?)
28
28
  end
29
29
 
30
+ def fallback_descendant
31
+ self
32
+ end
33
+
30
34
  def kind
31
35
  name.demodulize.underscore
32
36
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsm_models
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dimitrij Denissenko