magic_sti 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/magic_sti.rb CHANGED
@@ -1,5 +1,22 @@
1
1
  require "magic_sti/version"
2
2
 
3
- module MagicSti
4
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
- module MagicSti
2
- VERSION = "0.0.1"
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 = MagicSti::VERSION
16
+ gem.version = MagicSTI::VERSION
17
17
 
18
18
  gem.add_dependency "activesupport"
19
19
  gem.add_dependency "activerecord"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic_sti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: