class-table-inheritance 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/{README → README.markdown} +32 -18
- data/Rakefile +4 -2
- data/class-table-inheritance.gemspec +7 -1
- data/lib/class-table-inheritance/class-table-inheritance.rb +3 -3
- data/lib/class-table-inheritance/version.rb +2 -2
- data/test/class_table_inheritance_test.rb +1 -1
- data/test/test_helper.rb +4 -1
- metadata +86 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5a95bda292c5e755340b27be9fd90f957b01ecc47b73c89c177f572596a2f129
|
4
|
+
data.tar.gz: bd126cd28e8a4f7211d610c8316e50f76936db8cb0cc5204941292d1d4dc514f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74c2e34b1409d158dde93426294e15bea61cad76ed8e7855b39041350b5e7e5cff0e2a180d9e087fbf9244c8b5d282c2d3b35a882c842e055dde8c09e85383dc
|
7
|
+
data.tar.gz: 1d2bfb4824571a4dcf873846c07693f8ba949d5b580ba8327a8cd57135a0a5c6d57c62d81861aab15e3d6015553174b6de488e2c76ac2f0ca04ab57587d321a9
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/{README → README.markdown}
RENAMED
@@ -1,18 +1,25 @@
|
|
1
1
|
Change log
|
2
|
-
|
2
|
+
----------
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
### 1.3.1
|
5
|
+
|
6
|
+
* Removed 'set_primary_key' deprecation warning
|
7
|
+
* Make the gem depencies explicit and require ActiveRecord 4.x or 5.0
|
8
|
+
|
9
|
+
|
10
|
+
### 1.3.0
|
11
|
+
* Now you can inherits from and to modules like inherits_from 'Module::Model', see the the name of
|
12
|
+
field must be module_model_id:integer thanks for Marc Remolt (https://github.com/mremolt).
|
6
13
|
* Unit test
|
7
14
|
|
8
15
|
|
9
|
-
|
10
|
-
|
16
|
+
Note about version
|
17
|
+
------------------
|
11
18
|
|
12
19
|
If you are using Rails 2.3.8 or other version < 3, you have to use the version 1.1.x of this plugin, for Rails 3 you need to use the version 1.2.x or master of this plugin.
|
13
20
|
|
14
|
-
ClassTableInheritance 1.
|
15
|
-
|
21
|
+
ClassTableInheritance 1.3.0
|
22
|
+
---------------------------
|
16
23
|
|
17
24
|
This is an ActiveRecord plugin designed to allow
|
18
25
|
simple multiple table (class) inheritance.
|
@@ -22,15 +29,16 @@ ClassTableInheritance 1.2.1
|
|
22
29
|
Multiple Table Inheritance with ActiveRecord => http://mediumexposure.com/multiple-table-inheritance-active-record/
|
23
30
|
|
24
31
|
How to install
|
25
|
-
|
32
|
+
--------------
|
26
33
|
|
27
34
|
gem install class-table-inheritance
|
28
35
|
|
29
36
|
Example
|
30
|
-
|
37
|
+
-------
|
31
38
|
|
32
|
-
|
39
|
+
### Migrations
|
33
40
|
|
41
|
+
```ruby
|
34
42
|
create_table :products do |t|
|
35
43
|
t.string :description, :null => false
|
36
44
|
t.string :subtype # Only if you need access of both side see example
|
@@ -46,10 +54,11 @@ Example
|
|
46
54
|
t.string :year, :null => false
|
47
55
|
t.string :genre, :null => false
|
48
56
|
end
|
57
|
+
```
|
49
58
|
|
59
|
+
### Models
|
50
60
|
|
51
|
-
|
52
|
-
|
61
|
+
```ruby
|
53
62
|
class Product < ActiveRecord::Base
|
54
63
|
acts_as_superclass # only if you want top-down access.
|
55
64
|
end
|
@@ -78,12 +87,13 @@ Example
|
|
78
87
|
book.author = "Shakespeare, William"
|
79
88
|
book.price => 14.00
|
80
89
|
book.save
|
81
|
-
|
90
|
+
```
|
82
91
|
|
83
92
|
Module inheritance
|
84
|
-
|
85
|
-
# Migrations
|
93
|
+
------------------
|
86
94
|
|
95
|
+
### Migrations
|
96
|
+
```ruby
|
87
97
|
create_table :mod_users do |t|
|
88
98
|
t.string :name, :null => false
|
89
99
|
end
|
@@ -91,27 +101,31 @@ end
|
|
91
101
|
create_table :managers, :inherits => 'Mod::User' do |t|
|
92
102
|
t.string :salary, :null => false
|
93
103
|
end
|
104
|
+
```
|
94
105
|
|
95
|
-
|
106
|
+
### Models
|
96
107
|
|
108
|
+
```ruby
|
97
109
|
class Mod::User < ActiveRecord::Base
|
98
110
|
end
|
99
111
|
|
100
112
|
class Manager < ActiveRecord::Base
|
101
113
|
inherits_from 'Mod::User'
|
102
114
|
end
|
115
|
+
```
|
103
116
|
|
104
117
|
Top-down access (Polymorphic)
|
105
|
-
|
118
|
+
-----------------------------
|
106
119
|
|
107
120
|
if you want to access product and get field in the subclass do you need to create a field subtype:string in superclass and ad acts_as_superclass in superclass and now you can do like this.
|
108
121
|
|
122
|
+
```ruby
|
109
123
|
product = Product.find 1 # This is a Book instance.
|
110
124
|
product.author
|
111
125
|
|
112
126
|
product = Product.find 2 # This is a Video instance.
|
113
127
|
product.genre
|
114
|
-
|
128
|
+
```
|
115
129
|
|
116
130
|
if you need help contanct me: bfscordeiro (at) gmail.com .
|
117
131
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'bundler'
|
1
|
+
require 'bundler/setup'
|
2
2
|
require 'rake/testtask'
|
3
3
|
Bundler::GemHelper.install_tasks
|
4
4
|
|
@@ -8,4 +8,6 @@ Rake::TestTask.new do |t|
|
|
8
8
|
t.libs << 'test'
|
9
9
|
t.pattern = 'test/**/*_test.rb'
|
10
10
|
t.verbose = true
|
11
|
-
end
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :test
|
@@ -18,4 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
-
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'activerecord', '>=4', '<5.1'
|
23
|
+
|
24
|
+
s.add_development_dependency 'minitest-reporters','~>1.1'
|
25
|
+
s.add_development_dependency 'rake', '>=11'
|
26
|
+
s.add_development_dependency 'sqlite3', '~>1.3'
|
27
|
+
end
|
@@ -42,13 +42,13 @@ class ActiveRecord::Base
|
|
42
42
|
class_name = association_id.to_s.classify
|
43
43
|
end
|
44
44
|
|
45
|
-
# add an association
|
46
|
-
|
45
|
+
# add an association
|
46
|
+
belongs_to association_id, :class_name => class_name, :dependent => :destroy
|
47
47
|
|
48
48
|
|
49
49
|
# set the primary key, it' need because the generalized table doesn't have
|
50
50
|
# a field ID.
|
51
|
-
|
51
|
+
self.primary_key = "#{association_id}_id"
|
52
52
|
|
53
53
|
|
54
54
|
# Autobuild method to make a instance of association
|
@@ -1,3 +1,3 @@
|
|
1
1
|
class ClassTableInheritance
|
2
|
-
VERSION = "1.3.
|
3
|
-
end
|
2
|
+
VERSION = "1.3.1"
|
3
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/reporters'
|
3
4
|
require 'active_record'
|
4
5
|
require 'class-table-inheritance'
|
5
6
|
require 'yaml'
|
6
7
|
|
8
|
+
Minitest::Reporters.use!
|
9
|
+
|
7
10
|
database = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
8
11
|
ActiveRecord::Base.establish_connection(database['sqlite3'])
|
9
12
|
load(File.dirname(__FILE__) + "/schema.rb") if !File.exists?(database['sqlite3'][:database])
|
metadata
CHANGED
@@ -1,32 +1,88 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: class-table-inheritance
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.3.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.1
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Bruno Frank
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: minitest-reporters
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '11'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: sqlite3
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.3'
|
17
75
|
description: ActiveRecord plugin designed to allow simple multiple table (class) inheritance.
|
18
|
-
email:
|
76
|
+
email:
|
19
77
|
- bfscordeiro@gmail.com
|
20
78
|
executables: []
|
21
|
-
|
22
79
|
extensions: []
|
23
|
-
|
24
80
|
extra_rdoc_files: []
|
25
|
-
|
26
|
-
|
27
|
-
- .
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".travis.yml"
|
28
84
|
- Gemfile
|
29
|
-
- README
|
85
|
+
- README.markdown
|
30
86
|
- Rakefile
|
31
87
|
- class-table-inheritance.gemspec
|
32
88
|
- init.rb
|
@@ -44,35 +100,30 @@ files:
|
|
44
100
|
- test/models/product.rb
|
45
101
|
- test/schema.rb
|
46
102
|
- test/test_helper.rb
|
47
|
-
has_rdoc: true
|
48
103
|
homepage: https://github.com/brunofrank/class-table-inheritance
|
49
104
|
licenses: []
|
50
|
-
|
105
|
+
metadata: {}
|
51
106
|
post_install_message:
|
52
107
|
rdoc_options: []
|
53
|
-
|
54
|
-
require_paths:
|
108
|
+
require_paths:
|
55
109
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
|
58
|
-
requirements:
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
59
112
|
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
|
64
|
-
requirements:
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
65
117
|
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
68
120
|
requirements: []
|
69
|
-
|
70
121
|
rubyforge_project: class-table-inheritance
|
71
|
-
rubygems_version:
|
122
|
+
rubygems_version: 2.7.7
|
72
123
|
signing_key:
|
73
|
-
specification_version:
|
124
|
+
specification_version: 4
|
74
125
|
summary: ActiveRecord plugin designed to allow simple multiple table (class) inheritance.
|
75
|
-
test_files:
|
126
|
+
test_files:
|
76
127
|
- test/class_table_inheritance_test.rb
|
77
128
|
- test/database.yml
|
78
129
|
- test/models/book.rb
|