Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to version 0.2.0 #22

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- 2.7
- 3.0
- 3.1
- 3.2
active-record-version:
- 6.0.0
- 6.1.0
- 7.0.0
- 7.1.0
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/gem-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Ruby Gem

on:
release:
types: [ published ]

jobs:
build:
name: Build + Publish
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v3
- name: Set up Ruby 3.1
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1

- name: Publish to RubyGems
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ class CreateCompanies < ActiveRecord::Migration
end
```

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.
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.

## Installation

_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._

Add this line to your application's Gemfile:

gem 'inheritance_integer_type'
Expand All @@ -42,28 +44,28 @@ Or install it yourself as:

The gem is pretty straightforward to use.

First, set the `integer_inheritance` value on each of the subclasses.
First, set the `integer_inheritance` value on each of the subclasses.
```ruby
class Firm < Company
self.integer_inheritance = 1
end

class Client < Company
self.integer_inheritance = 2
end

class PriorityClient < Client
self.integer_inheritance = 3
end
```


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.
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.

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.)
```ruby
class CompanyToIntegerType < ActiveRecord::Migration

def up
change_table :companies do |t|
t.integer :new_type
Expand Down
2 changes: 1 addition & 1 deletion lib/inheritance_integer_type/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module InheritanceIntegerType
VERSION = "0.1.3"
VERSION = "0.2.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the bump to 0.2.0 instead of say 0.1.4?

Copy link

@anthonyoconnorclio anthonyoconnorclio Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was because it is a more major change since this is dropping ruby 2.7 support.

Maybe breaking change is better wording than more major ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup what @anthonyoconnorclio said. Ruby 3 vs 2.7 (we can argue semver if you like) I wanted it to be clear that if you want to change ruby versions its a clear minor version bump rather and a incremental patch level bump.

Easier to clarify in the docs too, IMO.

end