Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/infraspecdev/state_machines_transactions
A ruby gem which persists the state transitions of the state_machines gem.
https://github.com/infraspecdev/state_machines_transactions
Last synced: 3 days ago
JSON representation
A ruby gem which persists the state transitions of the state_machines gem.
- Host: GitHub
- URL: https://github.com/infraspecdev/state_machines_transactions
- Owner: infraspecdev
- License: mit
- Created: 2023-07-31T07:53:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-31T11:10:17.000Z (over 1 year ago)
- Last Synced: 2024-11-08T09:28:26.927Z (about 2 months ago)
- Language: Ruby
- Size: 20.5 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# StateMachinesTransactions
This gem persists the state transitions of state_machines gem. The transactions (transition data) can be used to represent the path a stateful object took to reach the current state.## Installation
Add this line to your application's Gemfile:```ruby
gem "state_machines_transactions"
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install state_machines_transactions
```## Usage
Generate the database migration for state_machines_transactions table using:
```bash
$ rails generate state_machine_transactions
```And then execute:
```bash
$ rails db:migrate
```Add `audit_transition` inside your state machine to persist the state transitions.
```ruby
state_machine :state, initial: :parked do
audit_transitionstate :parked
state :idling
end
```Use `StateMachinesTransaction` model to fetch the transactions. The schema is:
```ruby
create_table "state_machines_transactions", force: :cascade do |t|
t.string "object_type"
t.integer "object_id"
t.string "state_field"
t.string "event"
t.string "from_state"
t.string "to_state"
t.string "status"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
```## Contributing
1. Fork it ( https://github.com/infraspecdev/state_machines_transactions/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).