inheritance_integer_type 0.1.3 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e932d673791b85556b6b801aaa5c95bac18874349a439f66a5f8e0caa86b057f
4
- data.tar.gz: cba578bdfa831665545c8d434d217352d7cacb5e5d6e127be56f2752e6dce438
3
+ metadata.gz: 551dfc8dfbea0b8974b785270586f7d4cea95ebac1d036d3047424936a30c5cb
4
+ data.tar.gz: f91d49631848cc6d09e261ffb38bbbb4840cde45948b77783e77538222573213
5
5
  SHA512:
6
- metadata.gz: 995c8ac0ec86a511f2e3be2af931edea4b60e0989a509807b51e3f3ea5258145919921808bea74ad8267e767d464b53b814fdb9c9999c2bb3619018cffd9844f
7
- data.tar.gz: 8c87eba6859ed899affdd8ffa2344bc93d38d5631855a3057eced8efb223b17e8df3a5abaacd638814f2a4bf8ce6aeb85dad4530ec5284bbf2e9af25aab585e4
6
+ metadata.gz: f831ed5b80b8304c062fcab070ff2f550a77a64a3d6390f3954b9ec514f5ed84528b7eafc0d503ad7d9ed2e1030cef372aed5149671c974489ec2e72a2ed3c8e
7
+ data.tar.gz: ce968892056689821bfcd3b4e7b7120daef0923968665d7b71b94b5c81ff4666ac8fbeb56e2f0501810bb39f3eefec37b3d939b325962ccc60736259f406ffbd
@@ -0,0 +1,30 @@
1
+ ---
2
+ name: CI
3
+
4
+ on:
5
+ workflow_dispatch:
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ ruby-version:
18
+ - "3.0"
19
+ - "3.1"
20
+ - "3.2"
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: "${{ matrix.ruby-version }}"
26
+ bundler-cache: true
27
+ - name: Run tests
28
+ run: |
29
+ bundle exec appraisal install
30
+ bundle exec appraisal rspec --format documentation
@@ -0,0 +1,30 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ release:
5
+ types: [ published ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby 3.1
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 3.1
20
+
21
+ - name: Publish to RubyGems
22
+ env:
23
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push *.gem
data/.gitignore CHANGED
@@ -24,6 +24,11 @@ build/
24
24
  /.bundle/
25
25
  /lib/bundler/man/
26
26
 
27
+ Gemfile.lock
28
+
29
+ # Do not copy generated appraisal Gemfiles
30
+ gemfiles/*
31
+
27
32
  # for a library or gem, you might want to ignore these files since the code is
28
33
  # intended to run in multiple environments; otherwise, check them in:
29
34
  # Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.4
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise "activerecord-6.1" do
2
+ gem "activerecord", "~> 6.1.0"
3
+ gem "concurrent-ruby", "1.3.4"
4
+ end
5
+
6
+ appraise "activerecord-7.0" do
7
+ gem "activerecord", "~> 7.0.0"
8
+ gem "concurrent-ruby", "1.3.4"
9
+ end
10
+
11
+ appraise "activerecord-7.1" do
12
+ gem "activerecord", "~> 7.1.0"
13
+ gem "concurrent-ruby"
14
+ end
data/Gemfile CHANGED
@@ -2,3 +2,20 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in inheritance_integer_type.gemspec
4
4
  gemspec
5
+
6
+ ar_version = ENV["ACTIVE_RECORD_VERSION"] || "default"
7
+
8
+ ar = case ar_version
9
+ when "master"
10
+ { github: "rails/rails" }
11
+ when "default"
12
+ ">= 6.0"
13
+ else
14
+ "~> #{ar_version}"
15
+ end
16
+
17
+ gem "activerecord", ar
18
+
19
+ group :development, :test do
20
+ gem "appraisal", "2.5.0"
21
+ end
data/README.md CHANGED
@@ -22,10 +22,12 @@ class CreateCompanies < ActiveRecord::Migration
22
22
  end
23
23
  ```
24
24
 
25
- The problem with this approach is that `type` is a string (and by default it is 255 characters). This is a little ridiculous. For comparison, if we had a state machine with X states, would we describe the states with strings `"State1", "State2", etc` or would we just enumerate the state column and make it an integer? This gem will allow us to use an integer for the `type` column.
25
+ The problem with this approach is that `type` is a string (and by default it is 255 characters). This is a little ridiculous. For comparison, if we had a state machine with X states, would we describe the states with strings `"State1", "State2", etc` or would we just enumerate the state column and make it an integer? This gem will allow us to use an integer for the `type` column.
26
26
 
27
27
  ## Installation
28
28
 
29
+ _Current versions of this gem (>= v0.2.0) only support Ruby 3+ and ActiveRecord >= v6.1. For Ruby <= v2.7 or ActiveRecord <= 6.0, use v0.1.3._
30
+
29
31
  Add this line to your application's Gemfile:
30
32
 
31
33
  gem 'inheritance_integer_type'
@@ -42,28 +44,28 @@ Or install it yourself as:
42
44
 
43
45
  The gem is pretty straightforward to use.
44
46
 
45
- First, set the `integer_inheritance` value on each of the subclasses.
47
+ First, set the `integer_inheritance` value on each of the subclasses.
46
48
  ```ruby
47
49
  class Firm < Company
48
50
  self.integer_inheritance = 1
49
51
  end
50
-
52
+
51
53
  class Client < Company
52
54
  self.integer_inheritance = 2
53
55
  end
54
-
56
+
55
57
  class PriorityClient < Client
56
58
  self.integer_inheritance = 3
57
59
  end
58
60
  ```
59
61
 
60
62
 
61
- Note: The mapping here can start from whatever integer you wish, but I would advise not using 0. The reason being that if you had a new class, for instance `PriorityFirm`, but forgot to include set the mapping, it would effectively get `to_i` called on it and stored in the database. `"Priority".to_i == 0`, so if your mapping included 0, this would create a weird bug.
63
+ Note: The mapping here can start from whatever integer you wish, but I would advise not using 0. The reason being that if you had a new class, for instance `PriorityFirm`, but forgot to include set the mapping, it would effectively get `to_i` called on it and stored in the database. `"Priority".to_i == 0`, so if your mapping included 0, this would create a weird bug.
62
64
 
63
65
  If you want to convert a polymorphic association that is already a string, you'll need to set up a migration. (Assuming SQL for the time being, but this should be pretty straightforward.)
64
66
  ```ruby
65
67
  class CompanyToIntegerType < ActiveRecord::Migration
66
-
68
+
67
69
  def up
68
70
  change_table :companies do |t|
69
71
  t.integer :new_type
data/dev.yml ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ version: "2.0"
3
+
4
+ setup:
5
+ ruby: 3.1.4
6
+ bundler: 2.4.21
7
+
8
+ commands:
9
+ test:
10
+ summary: Run the project's specs
11
+ command: bundle exec appraisal rspec spec/
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "activerecord"
25
- spec.add_development_dependency "sqlite3", "~> 1.3.6"
24
+ spec.add_development_dependency "activerecord", ">= 5.2"
25
+ spec.add_development_dependency "sqlite3", "~> 1.4"
26
26
  spec.add_development_dependency "pry"
27
27
  end
@@ -13,7 +13,7 @@ module InheritanceIntegerType
13
13
  else
14
14
  begin
15
15
  if store_full_sti_class
16
- ActiveSupport::Dependencies.constantize(lookup)
16
+ lookup.constantize
17
17
  else
18
18
  compute_type(lookup)
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module InheritanceIntegerType
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.1"
3
3
  end
data/overlord.yml ADDED
@@ -0,0 +1,3 @@
1
+ tier: 3
2
+ owner: backend-infrastructure
3
+ classification: library
@@ -48,7 +48,7 @@ describe InheritanceIntegerType do
48
48
  describe "Has many associations" do
49
49
  let(:other) { Other.create }
50
50
  before do
51
- [base, left, deep].each{|a| a.update_attributes(other: other) }
51
+ [base, left, deep].each{|a| a.update_attribute(:other, other) }
52
52
  end
53
53
  subject { other }
54
54
  it "properly finds the classes through the association" do
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,7 @@ require 'support/belongs_to'
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.before(:suite) do
12
- ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations").migrate
12
+ ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations", ::ActiveRecord::SchemaMigration).migrate
13
13
  end
14
14
 
15
15
  # No need to return the run the down migration after the test
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inheritance_integer_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle d'Oliveira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2025-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '5.2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '5.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.3.6
75
+ version: '1.4'
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: 1.3.6
82
+ version: '1.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -102,17 +102,22 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/ci.yaml"
106
+ - ".github/workflows/gem-push.yaml"
105
107
  - ".gitignore"
108
+ - ".ruby-version"
109
+ - Appraisals
106
110
  - Gemfile
107
- - Gemfile.lock
108
111
  - LICENSE
109
112
  - LICENSE.txt
110
113
  - README.md
111
114
  - Rakefile
115
+ - dev.yml
112
116
  - inheritance_integer_type.gemspec
113
117
  - lib/inheritance_integer_type.rb
114
118
  - lib/inheritance_integer_type/extensions.rb
115
119
  - lib/inheritance_integer_type/version.rb
120
+ - overlord.yml
116
121
  - spec/inheritance_integer_type_spec.rb
117
122
  - spec/spec_helper.rb
118
123
  - spec/spec_helper~
@@ -130,7 +135,7 @@ homepage: ''
130
135
  licenses:
131
136
  - MIT
132
137
  metadata: {}
133
- post_install_message:
138
+ post_install_message:
134
139
  rdoc_options: []
135
140
  require_paths:
136
141
  - lib
@@ -145,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
150
  - !ruby/object:Gem::Version
146
151
  version: '0'
147
152
  requirements: []
148
- rubygems_version: 3.0.3
149
- signing_key:
153
+ rubygems_version: 3.3.27
154
+ signing_key:
150
155
  specification_version: 4
151
156
  summary: Allow the type field in teh DB to be an integer rather than a string
152
157
  test_files:
data/Gemfile.lock DELETED
@@ -1,62 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- inheritance_integer_type (0.1.2)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
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)
21
- coderay (1.1.2)
22
- concurrent-ruby (1.0.5)
23
- diff-lcs (1.2.5)
24
- i18n (1.0.0)
25
- concurrent-ruby (~> 1.0)
26
- method_source (0.9.0)
27
- minitest (5.11.3)
28
- pry (0.11.3)
29
- coderay (~> 1.1.0)
30
- method_source (~> 0.9.0)
31
- rake (10.3.2)
32
- rspec (3.0.0)
33
- rspec-core (~> 3.0.0)
34
- rspec-expectations (~> 3.0.0)
35
- rspec-mocks (~> 3.0.0)
36
- rspec-core (3.0.0)
37
- rspec-support (~> 3.0.0)
38
- rspec-expectations (3.0.0)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.0.0)
41
- rspec-mocks (3.0.1)
42
- rspec-support (~> 3.0.0)
43
- rspec-support (3.0.0)
44
- sqlite3 (1.3.13)
45
- thread_safe (0.3.6)
46
- tzinfo (1.2.5)
47
- thread_safe (~> 0.1)
48
-
49
- PLATFORMS
50
- ruby
51
-
52
- DEPENDENCIES
53
- activerecord
54
- bundler (~> 1.6)
55
- inheritance_integer_type!
56
- pry
57
- rake
58
- rspec
59
- sqlite3 (~> 1.3.6)
60
-
61
- BUNDLED WITH
62
- 1.16.6