polymorphic_integer_type 1.0.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/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +137 -0
- data/Rakefile +1 -0
- data/lib/polymorphic_integer_type.rb +5 -0
- data/lib/polymorphic_integer_type/extensions.rb +95 -0
- data/lib/polymorphic_integer_type/mapping.rb +20 -0
- data/lib/polymorphic_integer_type/version.rb +3 -0
- data/polymorphic_integer_type.gemspec +28 -0
- data/spec/polymorphic_integer_type_spec.rb +135 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/animal.rb +10 -0
- data/spec/support/configuration.rb +6 -0
- data/spec/support/drink.rb +9 -0
- data/spec/support/food.rb +8 -0
- data/spec/support/link.rb +8 -0
- data/spec/support/migrations/1_create_link_table.rb +18 -0
- data/spec/support/migrations/2_create_animal_table.rb +17 -0
- data/spec/support/migrations/3_create_person_table.rb +13 -0
- data/spec/support/migrations/4_create_food_table.rb +15 -0
- data/spec/support/migrations/5_create_drink_table.rb +13 -0
- data/spec/support/person.rb +11 -0
- metadata +180 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kyle d'Oliveira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# PolymorphicIntegerType
|
2
|
+
|
3
|
+
Rails' polymorphic assocaitions are pretty useful. The example they give to set it up looks like:
|
4
|
+
```ruby
|
5
|
+
class Picture < ActiveRecord::Base
|
6
|
+
belongs_to :imageable, polymorphic: true
|
7
|
+
end
|
8
|
+
|
9
|
+
class Employee < ActiveRecord::Base
|
10
|
+
has_many :pictures, as: :imageable
|
11
|
+
end
|
12
|
+
|
13
|
+
class Product < ActiveRecord::Base
|
14
|
+
has_many :pictures, as: :imageable
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
With a migration that looks like:
|
19
|
+
```ruby
|
20
|
+
class CreatePictures < ActiveRecord::Migration
|
21
|
+
def change
|
22
|
+
create_table :pictures do |t|
|
23
|
+
t.string :name
|
24
|
+
t.integer :imageable_id
|
25
|
+
t.string :imageable_type
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
The problem with this approach is the `imageable_type` is a string (and by default it is 255 characters). This is a little rediculous. For comparison, if we had a state machine with X states, would be describe the states with strings `"State1", "State2", etc` or would be just enumerate the state column and make it an integer. This gem will make it so we can use an integer for the `imageable_type` column.
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
gem 'polymorphic_integer_type'
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
$ bundle
|
43
|
+
|
44
|
+
Or install it yourself as:
|
45
|
+
|
46
|
+
$ gem install polymorphic_integer_type
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
The gem is pretty straightforward to use.
|
51
|
+
|
52
|
+
First, include the extensions module and add the `integer_type` option to the assocaitions that are going to be using this. (That way it will play nicely with polymorphic association you would rather the type remain as a string)
|
53
|
+
```ruby
|
54
|
+
class Picture < ActiveRecord::Base
|
55
|
+
include PolymorphicIntegerType::Extensions
|
56
|
+
belongs_to :imageable, polymorphic: true, :integer_type => true
|
57
|
+
end
|
58
|
+
|
59
|
+
class Employee < ActiveRecord::Base
|
60
|
+
include PolymorphicIntegerType::Extensions
|
61
|
+
has_many :pictures, as: :imageable, :integer_type => true
|
62
|
+
end
|
63
|
+
|
64
|
+
class Product < ActiveRecord::Base
|
65
|
+
include PolymorphicIntegerType::Extensions
|
66
|
+
has_many :pictures, as: :imageable, :integer_type => true
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
Second, you need to create a mapping for the polymorphic associations. This should be loaded before the models. Putting it in an initializer is good (`config/initializers/polymorphic_type_mapping.rb`)
|
71
|
+
```ruby
|
72
|
+
PolymorphicIntegerType::Mapping.configuration do |config|
|
73
|
+
|
74
|
+
config.add :imageable, {1 => "Employee", 2 => "Product" }
|
75
|
+
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Note: The mapping here can start from whatever integer you wish, but I would advise not to use 0. The reason being that if you had a new class, for instance `Avatar`, and also wanted to use this polymorphic association but forgot to include it in the mapping, it would effectively get `to_i` called on it and stored in the database. `"Avatar".to_i == 0` so if your mapping included 0, this would create a weird bug.
|
80
|
+
|
81
|
+
If you want to migrate from a polymorphic association that is already a string you'll need to setup a migration (assuming sql for the time being. But this should be pretty straightforward)
|
82
|
+
```ruby
|
83
|
+
class PictureToPolymorphicIntegerType < ActiveRecord::Migration
|
84
|
+
|
85
|
+
def up
|
86
|
+
execute <<-SQL
|
87
|
+
ALTER TABLE pictures
|
88
|
+
ADD COLUMN new_imageable_type INTEGER
|
89
|
+
SQL
|
90
|
+
|
91
|
+
execute <<-SQL
|
92
|
+
UPDATE reminders
|
93
|
+
SET new_imageable_type = CASE imageable_type
|
94
|
+
WHEN 'Employee' THEN 1
|
95
|
+
WHEN 'Product' THEN 2
|
96
|
+
END
|
97
|
+
SQL
|
98
|
+
execute <<-SQL
|
99
|
+
ALTER TABLE pictures
|
100
|
+
DROP COLUMN imageable_type,
|
101
|
+
CHANGE COLUMN new_imageable_type imageable_type INTEGER
|
102
|
+
SQL
|
103
|
+
end
|
104
|
+
|
105
|
+
def down
|
106
|
+
execute <<-SQL
|
107
|
+
ALTER TABLE pictures
|
108
|
+
ADD COLUMN new_imageable_type VARCHAR(255)
|
109
|
+
SQL
|
110
|
+
|
111
|
+
execute <<-SQL
|
112
|
+
UPDATE picture
|
113
|
+
SET new_imageable_type = CASE imageable_type
|
114
|
+
WHEN 1 THEN 'Employee'
|
115
|
+
WHEN 2 THEN 'Product'
|
116
|
+
END
|
117
|
+
SQL
|
118
|
+
execute <<-SQL
|
119
|
+
ALTER TABLE picture
|
120
|
+
DROP COLUMN imageable_type,
|
121
|
+
CHANGE COLUMN new_imageable_type imageable_type VARCHAR(255)
|
122
|
+
SQL
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
Lastly, you will need to be careful of any place where you are doing raw sql queries with the string (`imageable_type = 'Employee'`). They should use the integer instead
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
## Contributing
|
132
|
+
|
133
|
+
1. Fork it
|
134
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
135
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
136
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
137
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module PolymorphicIntegerType
|
2
|
+
|
3
|
+
module Extensions
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def belongs_to(name, options = {})
|
7
|
+
integer_type = options.delete :integer_type
|
8
|
+
super
|
9
|
+
if options[:polymorphic] && integer_type
|
10
|
+
mapping = PolymorphicIntegerType::Mapping[name]
|
11
|
+
foreign_type = reflections[name].foreign_type
|
12
|
+
self._polymorphic_foreign_types << foreign_type
|
13
|
+
|
14
|
+
define_method foreign_type do
|
15
|
+
t = super()
|
16
|
+
mapping[t]
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method "#{foreign_type}=" do |klass|
|
20
|
+
enum = mapping.key(klass.to_s) || klass
|
21
|
+
super(enum)
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method "#{name}=" do |record|
|
25
|
+
super(record)
|
26
|
+
send("#{foreign_type}=", record.class)
|
27
|
+
end
|
28
|
+
|
29
|
+
validate do
|
30
|
+
t = send(foreign_type)
|
31
|
+
unless t.nil? || mapping.values.include?(t)
|
32
|
+
errors.add(foreign_type, "is not included in the mapping")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def remove_type_and_establish_mapping(name, options)
|
39
|
+
integer_type = options.delete :integer_type
|
40
|
+
if options[:as] && integer_type
|
41
|
+
poly_type = options.delete(:as)
|
42
|
+
mapping = PolymorphicIntegerType::Mapping[poly_type]
|
43
|
+
klass_mapping = (mapping||{}).key self.sti_name
|
44
|
+
raise "Polymorphic Class Mapping is missing for #{poly_type}" unless klass_mapping
|
45
|
+
|
46
|
+
options[:foreign_key] ||= "#{poly_type}_id"
|
47
|
+
foreign_type = options.delete(:foreign_type) || "#{poly_type}_type"
|
48
|
+
options[:conditions] ||= {foreign_type => klass_mapping.to_i}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def has_many(name, options = {}, &extension)
|
53
|
+
remove_type_and_establish_mapping(name, options)
|
54
|
+
super(name, options, &extension)
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_one(name, options)
|
58
|
+
remove_type_and_establish_mapping(name, options)
|
59
|
+
super(name, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.included(base)
|
66
|
+
base.class_eval {
|
67
|
+
cattr_accessor :_polymorphic_foreign_types
|
68
|
+
self._polymorphic_foreign_types = []
|
69
|
+
}
|
70
|
+
base.extend(ClassMethods)
|
71
|
+
end
|
72
|
+
|
73
|
+
def _polymorphic_foreign_types
|
74
|
+
self.class._polymorphic_foreign_types
|
75
|
+
end
|
76
|
+
|
77
|
+
def [](value)
|
78
|
+
if _polymorphic_foreign_types.include?(value)
|
79
|
+
send(value)
|
80
|
+
else
|
81
|
+
super(value)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def []=(attr_name, value)
|
86
|
+
if _polymorphic_foreign_types.include?(attr_name)
|
87
|
+
send("#{attr_name}=", value)
|
88
|
+
else
|
89
|
+
super(attr_name, value)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PolymorphicIntegerType
|
2
|
+
|
3
|
+
class Mapping
|
4
|
+
@@mapping = {}
|
5
|
+
|
6
|
+
def self.configuration
|
7
|
+
yield(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add(as, mapping)
|
11
|
+
@@mapping[as] = mapping
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.[](as)
|
15
|
+
@@mapping[as] || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'polymorphic_integer_type/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "polymorphic_integer_type"
|
8
|
+
spec.version = PolymorphicIntegerType::VERSION
|
9
|
+
spec.authors = ["Kyle d'Oliveira"]
|
10
|
+
spec.email = ["kyle@goclio.com"]
|
11
|
+
spec.description = %q{Allows the *_type field in the DB to be an integer rather than a string}
|
12
|
+
spec.summary = %q{Use integers rather than strings for the _type field}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.2"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "activerecord", "3.2.11"
|
25
|
+
spec.add_development_dependency "mysql", "2.8.1"
|
26
|
+
spec.add_development_dependency "debugger"
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PolymorphicIntegerType do
|
4
|
+
|
5
|
+
let(:owner) { Person.create(:name => "Kyle") }
|
6
|
+
let(:dog) { Animal.create(:name => "Bela", :kind => "Dog", :owner => owner) }
|
7
|
+
let(:cat) { Animal.create(:name => "Alexi", :kind => "Cat") }
|
8
|
+
|
9
|
+
|
10
|
+
let(:kibble) { Food.create(:name => "Kibble") }
|
11
|
+
let(:chocolate) { Food.create(:name => "Choclate") }
|
12
|
+
|
13
|
+
|
14
|
+
let(:milk) { Drink.create(:name => "milk") }
|
15
|
+
let(:water) { Drink.create(:name => "Water") }
|
16
|
+
let(:whiskey) { Drink.create(:name => "Whiskey") }
|
17
|
+
|
18
|
+
let(:link) { Link.create(:source => source, :target => target) }
|
19
|
+
|
20
|
+
shared_examples "proper source" do
|
21
|
+
it "should have the proper id, type and object for the source" do
|
22
|
+
expect(link.source_id).to eql source.id
|
23
|
+
expect(link.source_type).to eql source.class.to_s
|
24
|
+
expect(link.source).to eql source
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_examples "proper target" do
|
29
|
+
it "should have the proper id, type and object for the target" do
|
30
|
+
expect(link.target_id).to eql target.id
|
31
|
+
expect(link.target_type).to eql target.class.to_s
|
32
|
+
expect(link.target).to eql target
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "When a link is created through an association" do
|
37
|
+
let(:link) { source.source_links.create }
|
38
|
+
let(:source) { cat }
|
39
|
+
include_examples "proper source"
|
40
|
+
|
41
|
+
context "and the link is accessed through the associations" do
|
42
|
+
before { link }
|
43
|
+
|
44
|
+
it "should have the proper source" do
|
45
|
+
expect(source.source_links[0].source).to eql source
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
context "When a link is given polymorphic record" do
|
51
|
+
let(:link) { Link.create(:source => source) }
|
52
|
+
let(:source) { cat }
|
53
|
+
include_examples "proper source"
|
54
|
+
|
55
|
+
context "and when it already has a polymorphic record" do
|
56
|
+
let(:target) { kibble }
|
57
|
+
before { link.update_attributes(:target => target) }
|
58
|
+
|
59
|
+
include_examples "proper source"
|
60
|
+
include_examples "proper target"
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
context "When a link is given polymorphic id and type" do
|
67
|
+
let(:link) { Link.create(:source_id => source.id, :source_type => source.class.to_s) }
|
68
|
+
let(:source) { cat }
|
69
|
+
include_examples "proper source"
|
70
|
+
|
71
|
+
context "and when it already has a polymorphic id and type" do
|
72
|
+
let(:target) { kibble }
|
73
|
+
before { link.update_attributes(:target_id => target.id, :target_type => target.class.to_s) }
|
74
|
+
include_examples "proper source"
|
75
|
+
include_examples "proper target"
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "When using a relation to the links with eagar loading" do
|
82
|
+
let!(:links){
|
83
|
+
[Link.create(:source => source, :target => kibble),
|
84
|
+
Link.create(:source => source, :target => water)]
|
85
|
+
}
|
86
|
+
let(:source) { cat }
|
87
|
+
|
88
|
+
it "should be able to return the links and the targets" do
|
89
|
+
expect(cat.source_links).to match_array links
|
90
|
+
expect(cat.source_links.includes(:target).collect(&:target)).to match_array [water, kibble]
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context "When using a through relation to the links with eagar loading" do
|
97
|
+
let!(:links){
|
98
|
+
[Link.create(:source => source, :target => kibble),
|
99
|
+
Link.create(:source => source, :target => water)]
|
100
|
+
}
|
101
|
+
let(:source) { dog }
|
102
|
+
|
103
|
+
it "should be able to return the links and the targets" do
|
104
|
+
expect(owner.pet_source_links).to match_array links
|
105
|
+
expect(owner.pet_source_links.includes(:target).collect(&:target)).to match_array [water, kibble]
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
context "When eagar loading the polymorphic association" do
|
112
|
+
let(:link) { Link.create(:source_id => source.id, :source_type => source.class.to_s) }
|
113
|
+
let(:source) { cat }
|
114
|
+
|
115
|
+
context "and when there are multiples sources" do
|
116
|
+
let(:link_2) { Link.create(:source_id => source_2.id, :source_type => source_2.class.to_s) }
|
117
|
+
let(:source_2) { dog }
|
118
|
+
it "should be able to preload both associations" do
|
119
|
+
links = Link.includes(:source).where(:id => [link.id, link_2.id]).order(:id)
|
120
|
+
expect(links.first.source).to eql cat
|
121
|
+
expect(links.last.source).to eql dog
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should be able to preload the association" do
|
127
|
+
l = Link.includes(:source).where(:id => link.id).first
|
128
|
+
expect(l.source).to eql cat
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'support/active_record'
|
2
|
+
require 'polymorphic_integer_type'
|
3
|
+
require 'support/configuration'
|
4
|
+
require 'support/link'
|
5
|
+
require 'support/animal'
|
6
|
+
require 'support/person'
|
7
|
+
require 'support/food'
|
8
|
+
require 'support/drink'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
config.before(:suite) do
|
15
|
+
ActiveRecord::Migrator.up "#{File.dirname(__FILE__)}/support/migrations"
|
16
|
+
end
|
17
|
+
|
18
|
+
# No need to return the run the down migration after the test
|
19
|
+
# but useful while in development
|
20
|
+
# config.after(:suite) do
|
21
|
+
# ActiveRecord::Migrator.down "#{File.dirname(__FILE__)}/support/migrations"
|
22
|
+
# end
|
23
|
+
|
24
|
+
|
25
|
+
config.around do |example|
|
26
|
+
ActiveRecord::Base.transaction do
|
27
|
+
example.run
|
28
|
+
raise ActiveRecord::Rollback
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateLinkTable < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
create_table :links do |t|
|
5
|
+
t.integer :target_id
|
6
|
+
t.integer :target_type
|
7
|
+
t.integer :source_id
|
8
|
+
t.integer :source_type
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def down
|
13
|
+
drop_table :links
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Person < ActiveRecord::Base
|
2
|
+
|
3
|
+
include PolymorphicIntegerType::Extensions
|
4
|
+
|
5
|
+
has_many :pets, :class_name => "Animal", :foreign_key => :owner_id
|
6
|
+
has_many :source_links, :as => :source, :integer_type => true, :class_name => "Link"
|
7
|
+
|
8
|
+
has_many :pet_source_links, :class_name => "Link", :through => :pets, :source => :source_links
|
9
|
+
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polymorphic_integer_type
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kyle d'Oliveira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activerecord
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.2.11
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.2.11
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mysql
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.8.1
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.8.1
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: debugger
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Allows the *_type field in the DB to be an integer rather than a string
|
111
|
+
email:
|
112
|
+
- kyle@goclio.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/polymorphic_integer_type.rb
|
123
|
+
- lib/polymorphic_integer_type/extensions.rb
|
124
|
+
- lib/polymorphic_integer_type/mapping.rb
|
125
|
+
- lib/polymorphic_integer_type/version.rb
|
126
|
+
- polymorphic_integer_type.gemspec
|
127
|
+
- spec/polymorphic_integer_type_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/active_record.rb
|
130
|
+
- spec/support/animal.rb
|
131
|
+
- spec/support/configuration.rb
|
132
|
+
- spec/support/drink.rb
|
133
|
+
- spec/support/food.rb
|
134
|
+
- spec/support/link.rb
|
135
|
+
- spec/support/migrations/1_create_link_table.rb
|
136
|
+
- spec/support/migrations/2_create_animal_table.rb
|
137
|
+
- spec/support/migrations/3_create_person_table.rb
|
138
|
+
- spec/support/migrations/4_create_food_table.rb
|
139
|
+
- spec/support/migrations/5_create_drink_table.rb
|
140
|
+
- spec/support/person.rb
|
141
|
+
homepage: ''
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.8.25
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: Use integers rather than strings for the _type field
|
166
|
+
test_files:
|
167
|
+
- spec/polymorphic_integer_type_spec.rb
|
168
|
+
- spec/spec_helper.rb
|
169
|
+
- spec/support/active_record.rb
|
170
|
+
- spec/support/animal.rb
|
171
|
+
- spec/support/configuration.rb
|
172
|
+
- spec/support/drink.rb
|
173
|
+
- spec/support/food.rb
|
174
|
+
- spec/support/link.rb
|
175
|
+
- spec/support/migrations/1_create_link_table.rb
|
176
|
+
- spec/support/migrations/2_create_animal_table.rb
|
177
|
+
- spec/support/migrations/3_create_person_table.rb
|
178
|
+
- spec/support/migrations/4_create_food_table.rb
|
179
|
+
- spec/support/migrations/5_create_drink_table.rb
|
180
|
+
- spec/support/person.rb
|