class-table-inheritance 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{README.markdown → README.md} +10 -2
- data/class-table-inheritance.gemspec +3 -1
- data/lib/class-table-inheritance/class-table-inheritance.rb +9 -12
- data/lib/class-table-inheritance/inherits-migration.rb +4 -13
- data/lib/class-table-inheritance/version.rb +1 -1
- data/test/test_helper.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e27e0105847bc9bf4b3be11d2908984c1a74537c25d677552cc14308e7c4090
|
4
|
+
data.tar.gz: 90a3df095f9c9a177aceea9654950c461d3f17d9752267ad450478c1b1e779a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d85a2ec1e415c425c589355647d48c63fdf2029a97c3b8274a0d89f291c17cff381d32d1e6d231a35e540a55e4322c325a1ffad168828c4cb3bdced88eceb2
|
7
|
+
data.tar.gz: 7be4ebbb05a2544cc7a9797fc152324995b274c5835bc014935f3bc804df20a4961b6155bcb6514be3443ce587e4fc7207b6ada990f524722044c940cd4d7f88
|
@@ -1,6 +1,14 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/brunofrank/class-table-inheritance.svg?branch=master)](https://travis-ci.org/brunofrank/class-table-inheritance)
|
2
|
+
|
1
3
|
Change log
|
2
4
|
----------
|
3
5
|
|
6
|
+
### 1.4.0
|
7
|
+
|
8
|
+
* Add ActiveRecord 5.2 support
|
9
|
+
* Require Ruby 2.2 or newer.
|
10
|
+
|
11
|
+
|
4
12
|
### 1.3.1
|
5
13
|
|
6
14
|
* Removed 'set_primary_key' deprecation warning
|
@@ -41,7 +49,7 @@ Example
|
|
41
49
|
```ruby
|
42
50
|
create_table :products do |t|
|
43
51
|
t.string :description, :null => false
|
44
|
-
|
52
|
+
t.string :subtype # Only if you need access of both side see example
|
45
53
|
t.decimal :price
|
46
54
|
t.timestamps
|
47
55
|
end
|
@@ -60,7 +68,7 @@ Example
|
|
60
68
|
|
61
69
|
```ruby
|
62
70
|
class Product < ActiveRecord::Base
|
63
|
-
|
71
|
+
acts_as_superclass # only if you want top-down access.
|
64
72
|
end
|
65
73
|
|
66
74
|
class Book < ActiveRecord::Base
|
@@ -19,7 +19,9 @@ Gem::Specification.new do |s|
|
|
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.
|
22
|
+
s.required_ruby_version = '~> 2.2'
|
23
|
+
|
24
|
+
s.add_runtime_dependency 'activerecord', '>=4', '<6'
|
23
25
|
|
24
26
|
s.add_development_dependency 'minitest-reporters','~>1.1'
|
25
27
|
s.add_development_dependency 'rake', '>=11'
|
@@ -51,15 +51,12 @@ class ActiveRecord::Base
|
|
51
51
|
self.primary_key = "#{association_id}_id"
|
52
52
|
|
53
53
|
|
54
|
-
# Autobuild method to make
|
55
|
-
|
56
|
-
|
54
|
+
# Autobuild method to make an instance of association
|
55
|
+
m = const_set("#{association_id.to_s.camelize}Builder", Module.new)
|
56
|
+
m.send(:define_method, association_id) do
|
57
|
+
super() || send("build_#{association_id}")
|
57
58
|
end
|
58
|
-
|
59
|
-
|
60
|
-
# Set a method chain whith autobuild.
|
61
|
-
alias_method_chain association_id, :autobuild
|
62
|
-
|
59
|
+
prepend(m)
|
63
60
|
|
64
61
|
# bind the before save, this method call the save of association, and
|
65
62
|
# get our generated ID an set to association_id field.
|
@@ -106,9 +103,9 @@ class ActiveRecord::Base
|
|
106
103
|
# if the field is ID than i only bind that with the association field.
|
107
104
|
# this is needed to bypass the overflow problem when the ActiveRecord
|
108
105
|
# try to get the id to find the association.
|
109
|
-
|
106
|
+
if name == 'id'
|
110
107
|
self["#{association_id}_id"]
|
111
|
-
|
108
|
+
else
|
112
109
|
assoc = send(association_id)
|
113
110
|
assoc.send(name)
|
114
111
|
end
|
@@ -119,9 +116,9 @@ class ActiveRecord::Base
|
|
119
116
|
# if the field is ID than i only bind that with the association field.
|
120
117
|
# this is needed to bypass the overflow problem when the ActiveRecord
|
121
118
|
# try to get the id to find the association.
|
122
|
-
|
119
|
+
if name == 'id'
|
123
120
|
self["#{association_id}_id"] = new_value
|
124
|
-
|
121
|
+
else
|
125
122
|
assoc = send(association_id)
|
126
123
|
assoc.send("#{name}=", new_value)
|
127
124
|
end
|
@@ -1,17 +1,9 @@
|
|
1
|
-
|
2
|
-
module InheritsMigration
|
3
|
-
|
4
|
-
def self.included(base)
|
5
|
-
base.class_eval do
|
6
|
-
alias_method_chain :create_table , :inherits
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
1
|
+
module InheritsMigration
|
10
2
|
# Generate the association field.
|
11
|
-
def
|
3
|
+
def create_table(table_name, options = {}, &block)
|
12
4
|
options[:id] ||= false if options[:inherits]
|
13
5
|
|
14
|
-
|
6
|
+
super(table_name, options) do |table_defintion|
|
15
7
|
if options[:inherits]
|
16
8
|
if options[:inherits].kind_of?(String)
|
17
9
|
column_to_create = options[:inherits].gsub(/::/, '_').downcase
|
@@ -32,5 +24,4 @@ module InheritsMigration
|
|
32
24
|
end
|
33
25
|
end
|
34
26
|
|
35
|
-
ActiveRecord::
|
36
|
-
ActiveRecord::ConnectionAdapters::SchemaStatements::send(:include, InheritsMigration)
|
27
|
+
ActiveRecord::ConnectionAdapters::SchemaStatements.prepend(InheritsMigration)
|
data/test/test_helper.rb
CHANGED
@@ -9,7 +9,7 @@ Minitest::Reporters.use!
|
|
9
9
|
|
10
10
|
database = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
11
11
|
ActiveRecord::Base.establish_connection(database['sqlite3'])
|
12
|
-
load(File.dirname(__FILE__) + "/schema.rb") if !File.
|
12
|
+
load(File.dirname(__FILE__) + "/schema.rb") if !File.exist?(database['sqlite3'][:database])
|
13
13
|
|
14
14
|
require 'models/product'
|
15
15
|
require 'models/book'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class-table-inheritance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Frank
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: minitest-reporters
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ files:
|
|
82
82
|
- ".gitignore"
|
83
83
|
- ".travis.yml"
|
84
84
|
- Gemfile
|
85
|
-
- README.
|
85
|
+
- README.md
|
86
86
|
- Rakefile
|
87
87
|
- class-table-inheritance.gemspec
|
88
88
|
- init.rb
|
@@ -109,9 +109,9 @@ require_paths:
|
|
109
109
|
- lib
|
110
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- - "
|
112
|
+
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
114
|
+
version: '2.2'
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
117
|
- - ">="
|