inheritance_integer_type 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9a916703b732e9a89a88946d16cf6a29c9674fd0
4
- data.tar.gz: 8dcd46dded61c5168d8e964659887bb33768d343
2
+ SHA256:
3
+ metadata.gz: e932d673791b85556b6b801aaa5c95bac18874349a439f66a5f8e0caa86b057f
4
+ data.tar.gz: cba578bdfa831665545c8d434d217352d7cacb5e5d6e127be56f2752e6dce438
5
5
  SHA512:
6
- metadata.gz: 2bcf51124af5f9e4ebcf75b30dea1cff9f3e207da988b9b3dea327917e82367541c5ae6f4e852c07251e641f6bf79b316113c1cf01dff492794db13427105838
7
- data.tar.gz: 6abd3fc1aebc455713a8127adb040179abc993b73d2ffdf7433444f60d28fa8a367a183436bb334c9dd9509b7c140695bf4b7a3efb904f7bf9a9c95c94d1c487
6
+ metadata.gz: 995c8ac0ec86a511f2e3be2af931edea4b60e0989a509807b51e3f3ea5258145919921808bea74ad8267e767d464b53b814fdb9c9999c2bb3619018cffd9844f
7
+ data.tar.gz: 8c87eba6859ed899affdd8ffa2344bc93d38d5631855a3057eced8efb223b17e8df3a5abaacd638814f2a4bf8ce6aeb85dad4530ec5284bbf2e9af25aab585e4
@@ -6,25 +6,25 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (3.2.11)
10
- activesupport (= 3.2.11)
11
- builder (~> 3.0.0)
12
- activerecord (3.2.11)
13
- activemodel (= 3.2.11)
14
- activesupport (= 3.2.11)
15
- arel (~> 3.0.2)
16
- tzinfo (~> 0.3.29)
17
- activesupport (3.2.11)
18
- i18n (~> 0.6)
19
- multi_json (~> 1.0)
20
- arel (3.0.3)
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.6.9)
24
+ i18n (1.0.0)
25
+ concurrent-ruby (~> 1.0)
25
26
  method_source (0.9.0)
26
- multi_json (1.10.1)
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
- tzinfo (0.3.39)
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.1
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 "mysql2", "0.3.18"
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
- extend ActiveSupport::Concern
4
- module ClassMethods
5
-
6
- def integer_inheritance=(val)
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
- def find_sti_class(type_name)
11
- lookup = self._inheritance_mapping[type_name.to_i]
12
- if lookup
13
- if ActiveRecord::VERSION::MAJOR < 5
14
- super(lookup)
15
- else
16
- begin
17
- if store_full_sti_class
18
- ActiveSupport::Dependencies.constantize(lookup)
19
- else
20
- compute_type(lookup)
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
- end
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
- included do
42
- class << self
43
- def _inheritance_mapping
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
- def _inheritance_mapping=(val)
48
- @_inheritance_mapping = val
49
- end
37
+ def _inheritance_mapping
38
+ @_inheritance_mapping ||= (superclass == ActiveRecord::Base ? {} : superclass._inheritance_mapping.dup)
39
+ end
50
40
 
51
- def merge_mapping!(mapping)
52
- conflicts = _inheritance_mapping.keys & mapping.keys
53
- raise ArgumentError.new("Duplicate mapping detected for keys: #{conflicts}") if conflicts.any?
41
+ def _inheritance_mapping=(val)
42
+ @_inheritance_mapping = val
43
+ end
54
44
 
55
- _inheritance_mapping.merge!(mapping)
56
- end
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
- alias_method_chain :sti_name, :integer_types
59
- end
49
+ _inheritance_mapping.merge!(mapping)
60
50
  end
61
-
62
51
  end
52
+
63
53
  end
@@ -1,3 +1,3 @@
1
1
  module InheritanceIntegerType
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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::Migrator.up "#{File.dirname(__FILE__)}/support/migrations"
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 => "mysql2",
6
- :host => "localhost",
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)
@@ -1,6 +1,4 @@
1
1
  class Base < ActiveRecord::Base
2
- include InheritanceIntegerType::Extensions
3
-
4
2
  has_many :belongs_to
5
3
  belongs_to :other
6
4
 
@@ -1,4 +1,4 @@
1
- class CreateBaseTable < ActiveRecord::Migration
1
+ class CreateBaseTable < ActiveRecord::Migration[5.2]
2
2
 
3
3
  def change
4
4
  create_table :bases do |t|
@@ -1,4 +1,4 @@
1
- class CreateBelongToTable < ActiveRecord::Migration
1
+ class CreateBelongToTable < ActiveRecord::Migration[5.2]
2
2
 
3
3
  def change
4
4
  create_table :belongs_tos do |t|
@@ -1,4 +1,4 @@
1
- class CreateOtherTable < ActiveRecord::Migration
1
+ class CreateOtherTable < ActiveRecord::Migration[5.2]
2
2
 
3
3
  def change
4
4
  create_table :others do |t|
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.2
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: 2018-04-12 00:00:00.000000000 Z
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: mysql2
70
+ name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.3.18
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: 0.3.18
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
- rubyforge_project:
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