Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanety/rails_callback_ex
https://github.com/kanety/rails_callback_ex
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kanety/rails_callback_ex
- Owner: kanety
- License: mit
- Created: 2023-10-15T04:55:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-21T00:43:21.000Z (3 months ago)
- Last Synced: 2024-10-21T04:07:36.297Z (3 months ago)
- Language: Ruby
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# RailsCallbackEx
Insert/delete callbacks for rails.
## Dependencies
* ruby 3.0+
* rails 6.1+## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rails_callback_ex'
```Then execute:
$ bundle
## Usage
### Controller
Example:
```ruby
class SamplesController < ActionController::Base
before_action :action1
before_action :action2insert_before_action :new_action1, before: :action1
insert_before_action :new_action2, after: :action1
endSamplesController.__callbacks[:process_action].map(&:filter) #=> [:new_action1, :action1, :new_action2, :action2]
SamplesController.delete_before_action :new_action1
SamplesController.__callbacks[:process_action].map(&:filter) #=> [:action1, :new_action2, :action2]
```### Model
Example:
```ruby
class Sample < ActiveRecord::Base
before_save :action1
before_save :action2insert_before_save :new_action1, before: :action1
insert_before_save :new_action2, after: :action1
endSample.__callbacks[:save].map(&:filter) #=> [:new_action1, :action1, :new_action2, :action2]
Sample.delete_before_save :new_action1
Sample.__callbacks[:save].map(&:filter) #=> [:action1, :new_action2, :action2]
```Supported callbacks are `validation`, `save`, `create`, `update` and `destroy`.
### Job
Example:
```ruby
class SampleJob < ActiveJob::Base
before_perform :action1
before_perform :action2insert_before_perform :new_action1, before: :action1
insert_before_perform :new_action2, after: :action1
endSampleJob.__callbacks[:perform].map(&:filter) #=> [:new_action1, :action1, :new_action2, :action2]
SampleJob.delete_before_perform :new_action1
SampleJob.__callbacks[:perform].map(&:filter) #=> [:action1, :new_action2, :action2]
```Supported callbacks are `enqueue` and `perform`.
### Mailer
Example:
```ruby
class SampleMailer < ActionMailer::Base
before_deliver :action1
before_deliver :action2insert_before_deliver :new_action1, before: :action1
insert_before_deliver :new_action2, after: :action1
endSampleMailer.__callbacks[:deliver].map(&:filter) #=> [:new_action1, :action1, :new_action2, :action2]
SampleMailer.delete_before_deliver :new_action1
SampleMailer.__callbacks[:deliver].map(&:filter) #=> [:action1, :new_action2, :action2]
```Supported callback is `deliver`. Note that `deliver` callbacks can be used on rails >= 7.1.
## Contributing
Bug reports and pull requests are welcome at https://github.com/kanety/rails_callback_ex.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).