inheritance_integer_type 0.1.3 → 0.2.0

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: 5eed88208785bd41ac4e3b7959526aaa500c744d1d00e0914df67fc3d4595e37
4
+ data.tar.gz: b5309eae3ff8d8b826497ec05390a12b709d3b00fb9e3a6a28be89954b981101
5
5
  SHA512:
6
- metadata.gz: 995c8ac0ec86a511f2e3be2af931edea4b60e0989a509807b51e3f3ea5258145919921808bea74ad8267e767d464b53b814fdb9c9999c2bb3619018cffd9844f
7
- data.tar.gz: 8c87eba6859ed899affdd8ffa2344bc93d38d5631855a3057eced8efb223b17e8df3a5abaacd638814f2a4bf8ce6aeb85dad4530ec5284bbf2e9af25aab585e4
6
+ metadata.gz: 1bbd3b8a7f178423902628e11598c65352350c0f8c509e484597c003cee66b2decfa8cdb8fba5a0e322330211d71b3069ff99ba455df0edda2778389a28cb3b0
7
+ data.tar.gz: afba16f3559dc14dd7cae13c8bbdea82a12f9bd0860a6517d0e0971cb0dcf898a3cd3cbdb8530145254c683922c689c7b15791bb54ba58da4d98fe3c5d8daa8e
@@ -0,0 +1,47 @@
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
+ active-record-version:
22
+ - 6.1.0
23
+ - 7.0.0
24
+ - 7.1.0
25
+ exclude:
26
+ - ruby-version: 3.2
27
+ active-record-version: 6.0.0
28
+ - ruby-version: 3.2
29
+ active-record-version: 6.1.0
30
+ - ruby-version: 3.2
31
+ active-record-version: 7.0.0
32
+ - ruby-version: 3.1
33
+ active-record-version: 6.0.0
34
+ - ruby-version: 3.1
35
+ active-record-version: 6.1.0
36
+ - ruby-version: 3.0
37
+ active-record-version: 6.0.0
38
+ env:
39
+ ACTIVE_RECORD_VERSION: "${{ matrix.active-record-version }}"
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+ - uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: "${{ matrix.ruby-version }}"
45
+ bundler-cache: true
46
+ - name: Run tests
47
+ run: bundle exec 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,8 @@ build/
24
24
  /.bundle/
25
25
  /lib/bundler/man/
26
26
 
27
+ Gemfile.lock
28
+
27
29
  # for a library or gem, you might want to ignore these files since the code is
28
30
  # intended to run in multiple environments; otherwise, check them in:
29
31
  # Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.4
data/Gemfile CHANGED
@@ -2,3 +2,16 @@ 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
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 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.0"
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.0
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: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2024-06-12 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,21 @@ 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"
106
109
  - Gemfile
107
- - Gemfile.lock
108
110
  - LICENSE
109
111
  - LICENSE.txt
110
112
  - README.md
111
113
  - Rakefile
114
+ - dev.yml
112
115
  - inheritance_integer_type.gemspec
113
116
  - lib/inheritance_integer_type.rb
114
117
  - lib/inheritance_integer_type/extensions.rb
115
118
  - lib/inheritance_integer_type/version.rb
119
+ - overlord.yml
116
120
  - spec/inheritance_integer_type_spec.rb
117
121
  - spec/spec_helper.rb
118
122
  - spec/spec_helper~
@@ -145,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
149
  - !ruby/object:Gem::Version
146
150
  version: '0'
147
151
  requirements: []
148
- rubygems_version: 3.0.3
152
+ rubygems_version: 3.3.27
149
153
  signing_key:
150
154
  specification_version: 4
151
155
  summary: Allow the type field in teh DB to be an integer rather than a string
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