inheritance_integer_type 0.1.2 → 0.1.3
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.
- checksums.yaml +5 -5
- data/Gemfile.lock +22 -19
- data/inheritance_integer_type.gemspec +1 -1
- data/lib/inheritance_integer_type.rb +1 -6
- data/lib/inheritance_integer_type/extensions.rb +37 -47
- data/lib/inheritance_integer_type/version.rb +1 -1
- data/spec/spec_helper.rb +1 -3
- data/spec/support/active_record.rb +2 -5
- data/spec/support/base.rb +0 -2
- data/spec/support/migrations/1_create_base_table.rb +1 -1
- data/spec/support/migrations/2_create_belong_to_table.rb +1 -1
- data/spec/support/migrations/3_create_other_table.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e932d673791b85556b6b801aaa5c95bac18874349a439f66a5f8e0caa86b057f
|
4
|
+
data.tar.gz: cba578bdfa831665545c8d434d217352d7cacb5e5d6e127be56f2752e6dce438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 995c8ac0ec86a511f2e3be2af931edea4b60e0989a509807b51e3f3ea5258145919921808bea74ad8267e767d464b53b814fdb9c9999c2bb3619018cffd9844f
|
7
|
+
data.tar.gz: 8c87eba6859ed899affdd8ffa2344bc93d38d5631855a3057eced8efb223b17e8df3a5abaacd638814f2a4bf8ce6aeb85dad4530ec5284bbf2e9af25aab585e4
|
data/Gemfile.lock
CHANGED
@@ -6,25 +6,25 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (
|
10
|
-
activesupport (=
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
arel (
|
21
|
-
builder (3.0.4)
|
9
|
+
activemodel (5.2.0)
|
10
|
+
activesupport (= 5.2.0)
|
11
|
+
activerecord (5.2.0)
|
12
|
+
activemodel (= 5.2.0)
|
13
|
+
activesupport (= 5.2.0)
|
14
|
+
arel (>= 9.0)
|
15
|
+
activesupport (5.2.0)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
arel (9.0.0)
|
22
21
|
coderay (1.1.2)
|
22
|
+
concurrent-ruby (1.0.5)
|
23
23
|
diff-lcs (1.2.5)
|
24
|
-
i18n (0.
|
24
|
+
i18n (1.0.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
25
26
|
method_source (0.9.0)
|
26
|
-
|
27
|
-
mysql2 (0.3.18)
|
27
|
+
minitest (5.11.3)
|
28
28
|
pry (0.11.3)
|
29
29
|
coderay (~> 1.1.0)
|
30
30
|
method_source (~> 0.9.0)
|
@@ -41,7 +41,10 @@ GEM
|
|
41
41
|
rspec-mocks (3.0.1)
|
42
42
|
rspec-support (~> 3.0.0)
|
43
43
|
rspec-support (3.0.0)
|
44
|
-
|
44
|
+
sqlite3 (1.3.13)
|
45
|
+
thread_safe (0.3.6)
|
46
|
+
tzinfo (1.2.5)
|
47
|
+
thread_safe (~> 0.1)
|
45
48
|
|
46
49
|
PLATFORMS
|
47
50
|
ruby
|
@@ -50,10 +53,10 @@ DEPENDENCIES
|
|
50
53
|
activerecord
|
51
54
|
bundler (~> 1.6)
|
52
55
|
inheritance_integer_type!
|
53
|
-
mysql2 (= 0.3.18)
|
54
56
|
pry
|
55
57
|
rake
|
56
58
|
rspec
|
59
|
+
sqlite3 (~> 1.3.6)
|
57
60
|
|
58
61
|
BUNDLED WITH
|
59
|
-
1.16.
|
62
|
+
1.16.6
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
spec.add_development_dependency "activerecord"
|
25
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "sqlite3", "~> 1.3.6"
|
26
26
|
spec.add_development_dependency "pry"
|
27
27
|
end
|
@@ -2,10 +2,5 @@ require "inheritance_integer_type/version"
|
|
2
2
|
require "inheritance_integer_type/extensions"
|
3
3
|
|
4
4
|
class ActiveRecord::Base
|
5
|
-
|
6
|
-
def self.inherited(child_class)
|
7
|
-
child_class.include InheritanceIntegerType::Extensions
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
5
|
+
singleton_class.prepend(InheritanceIntegerType::Extensions)
|
11
6
|
end
|
@@ -1,63 +1,53 @@
|
|
1
1
|
module InheritanceIntegerType
|
2
2
|
module Extensions
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
self._inheritance_mapping[val] = sti_name_without_integer_types
|
8
|
-
end
|
3
|
+
def sti_name
|
4
|
+
klass = super
|
5
|
+
self._inheritance_mapping.key(klass) || klass
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
rescue NameError
|
23
|
-
raise SubclassNotFound,
|
24
|
-
"The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " +
|
25
|
-
"This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
|
26
|
-
"Please rename this column if you didn't intend it to be used for storing the inheritance class " +
|
27
|
-
"or overwrite #{name}.inheritance_column to use another column for that information."
|
8
|
+
def find_sti_class(type_name)
|
9
|
+
lookup = self._inheritance_mapping[type_name.to_i]
|
10
|
+
if lookup
|
11
|
+
if ActiveRecord::VERSION::MAJOR < 5
|
12
|
+
super(lookup)
|
13
|
+
else
|
14
|
+
begin
|
15
|
+
if store_full_sti_class
|
16
|
+
ActiveSupport::Dependencies.constantize(lookup)
|
17
|
+
else
|
18
|
+
compute_type(lookup)
|
28
19
|
end
|
20
|
+
rescue NameError
|
21
|
+
raise SubclassNotFound,
|
22
|
+
"The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " +
|
23
|
+
"This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
|
24
|
+
"Please rename this column if you didn't intend it to be used for storing the inheritance class " +
|
25
|
+
"or overwrite #{name}.inheritance_column to use another column for that information."
|
29
26
|
end
|
30
|
-
else
|
31
|
-
super
|
32
27
|
end
|
33
|
-
|
34
|
-
|
35
|
-
def sti_name_with_integer_types
|
36
|
-
klass = sti_name_without_integer_types
|
37
|
-
self._inheritance_mapping.key(klass) || klass
|
28
|
+
else
|
29
|
+
super
|
38
30
|
end
|
39
31
|
end
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@_inheritance_mapping ||= (superclass == ActiveRecord::Base ? {} : superclass._inheritance_mapping.dup)
|
45
|
-
end
|
33
|
+
def integer_inheritance=(val)
|
34
|
+
self._inheritance_mapping[val] = method(:sti_name).super_method.call
|
35
|
+
end
|
46
36
|
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
def _inheritance_mapping
|
38
|
+
@_inheritance_mapping ||= (superclass == ActiveRecord::Base ? {} : superclass._inheritance_mapping.dup)
|
39
|
+
end
|
50
40
|
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
def _inheritance_mapping=(val)
|
42
|
+
@_inheritance_mapping = val
|
43
|
+
end
|
54
44
|
|
55
|
-
|
56
|
-
|
45
|
+
def merge_mapping!(mapping)
|
46
|
+
conflicts = _inheritance_mapping.keys & mapping.keys
|
47
|
+
raise ArgumentError.new("Duplicate mapping detected for keys: #{conflicts}") if conflicts.any?
|
57
48
|
|
58
|
-
|
59
|
-
end
|
49
|
+
_inheritance_mapping.merge!(mapping)
|
60
50
|
end
|
61
|
-
|
62
51
|
end
|
52
|
+
|
63
53
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,9 +8,8 @@ require 'support/other'
|
|
8
8
|
require 'support/belongs_to'
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|
11
|
-
|
12
11
|
config.before(:suite) do
|
13
|
-
ActiveRecord::
|
12
|
+
ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations").migrate
|
14
13
|
end
|
15
14
|
|
16
15
|
# No need to return the run the down migration after the test
|
@@ -19,7 +18,6 @@ RSpec.configure do |config|
|
|
19
18
|
# ActiveRecord::Migrator.down "#{File.dirname(__FILE__)}/support/migrations"
|
20
19
|
# end
|
21
20
|
|
22
|
-
|
23
21
|
config.around do |example|
|
24
22
|
ActiveRecord::Base.transaction do
|
25
23
|
example.run
|
@@ -2,10 +2,7 @@ require 'active_record'
|
|
2
2
|
Dir["#{File.dirname(__FILE__)}/migrations/*.rb"].each {|f| require f}
|
3
3
|
|
4
4
|
config = {
|
5
|
-
:adapter => "
|
6
|
-
:
|
7
|
-
:database => "inheritance_integer_type_test",
|
8
|
-
:username => "iit",
|
9
|
-
:password => ""
|
5
|
+
:adapter => "sqlite3",
|
6
|
+
:database => ":memory:",
|
10
7
|
}
|
11
8
|
ActiveRecord::Base.establish_connection(config)
|
data/spec/support/base.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inheritance_integer_type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle d'Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.3.6
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.3.6
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,8 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
|
-
|
149
|
-
rubygems_version: 2.5.2
|
148
|
+
rubygems_version: 3.0.3
|
150
149
|
signing_key:
|
151
150
|
specification_version: 4
|
152
151
|
summary: Allow the type field in teh DB to be an integer rather than a string
|