Skip to content

Commit

Permalink
Use after commit callback
Browse files Browse the repository at this point in the history
  • Loading branch information
drexed committed Sep 20, 2024
1 parent 3787310 commit 97f0106
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.5.1] - 2024-09-20
### Changed
- Use after commit on create instead of after create

## [1.5.0] - 2024-09-20
### Added
- Added uuid version option
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lite-uxid (1.5.0)
lite-uxid (1.5.1)

GEM
remote: https://rubygems.org/
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ Passable options are:
Add the following attribute to all corresponding tables.

```ruby
t.string :uxid, index: { unique: true }
# NOTE: null: true has to be set for HashID's
# since an ID must exist before it gets created.
t.string :uxid, null: false, index: { unique: true }
```

If using UUID and your database supports it:

```ruby
t.uuid :uxid, null: false, index: { unique: true }
```

**Setup**
Expand Down
1 change: 1 addition & 0 deletions lib/generators/lite/uxid/templates/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
config.nanoid_size = 21
config.ulid_charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
config.ulid_size = 26
config.uuid_version = 4
end
4 changes: 3 additions & 1 deletion lib/lite/uxid/record/hashid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Hashid
extend ActiveSupport::Concern

included do
after_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? }
after_commit :callback_generate_uxid!,
if: proc { respond_to?(:uxid) && !uxid? },
on: :create
end

class_methods do
Expand Down
3 changes: 2 additions & 1 deletion lib/lite/uxid/record/nanoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Nanoid
extend ActiveSupport::Concern

included do
before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? }
before_create :callback_generate_uxid!,
if: proc { respond_to?(:uxid) && !uxid? }
end

def uxid_prefix
Expand Down
3 changes: 2 additions & 1 deletion lib/lite/uxid/record/ulid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Ulid
extend ActiveSupport::Concern

included do
before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? }
before_create :callback_generate_uxid!,
if: proc { respond_to?(:uxid) && !uxid? }
end

private
Expand Down
3 changes: 2 additions & 1 deletion lib/lite/uxid/record/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Uuid
extend ActiveSupport::Concern

included do
before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? }
before_create :callback_generate_uxid!,
if: proc { respond_to?(:uxid) && !uxid? }
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/lite/uxid/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Lite
module Uxid

VERSION = "1.5.0"
VERSION = "1.5.1"

end
end

0 comments on commit 97f0106

Please sign in to comment.