magic_sti 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/magic_sti.rb +19 -2
- data/lib/magic_sti/version.rb +2 -2
- data/magic_sti.gemspec +1 -1
- metadata +1 -1
data/lib/magic_sti.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
require "magic_sti/version"
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module MagicSTI
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class << self
|
8
|
+
def new_with_cast(attrs = nil, options = {}, &blk)
|
9
|
+
type_col = inheritance_column.to_sym
|
10
|
+
attrs = attrs && attrs.symbolize_keys
|
11
|
+
type = attrs && attrs.delete(type_col)
|
12
|
+
klass = type && (type.is_a?(Class) ? type : type.constantize) || self
|
13
|
+
|
14
|
+
raise "Tried to instantiate #{klass} for #{self} (STI)" unless klass == self || klass < self
|
15
|
+
|
16
|
+
klass.new_without_cast(attrs, options, &blk)
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method_chain :new, :cast
|
20
|
+
end
|
21
|
+
end
|
5
22
|
end
|
data/lib/magic_sti/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0
|
1
|
+
module MagicSTI
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
data/magic_sti.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.name = "magic_sti"
|
15
15
|
gem.require_paths = ["lib"]
|
16
|
-
gem.version =
|
16
|
+
gem.version = MagicSTI::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency "activesupport"
|
19
19
|
gem.add_dependency "activerecord"
|