Skip to content

Repository files navigation

Current Status

ruby 4.0

ruby 3.0 ruby 3.1 ruby 3.2 ruby 3.3 ruby 3.4

ruby 2.6 ruby 2.7

100% Test Coverage License: MIT Gem Version

Index


Simple State Management for ActiveRecord!

The state, the whole state and nothing but the state!

Why StateGate?

StateGate is built on the belief that ActiveRecord is already great at managing state via validations. We provide the 'gate' to ensure valid transitions, without the overhead of event DSLs and complex guard logic.

Feature Description
Strict States only defined states can be set
Strict Transitions only defined transitions are allowed
No Guarding ActiveRecord Validations are better than guard clauses
No Eventing simply change state within normal model methods
Fast Fail exceptions are raised before accessing the DB or triggering any callbacks
No Ambiguous Result state changes succeed, or raise an exception - no need to check the response
Easy Testing built-in matchers for RSpec & Minitest make testing much easier
Simple to Implement with a simple DSL, StateGate is intuitive and easy to use

Requirements

  • Ruby 2.6+
  • ActiveRecord 5.0+

Installation

Add this line to your Gemfile:

gem 'state_gate'


Summary

A quick list of StateGate's creation, configuration, class & instance methods. Each method links to a more in-depth explanation within the Wiki.

...creation

Creating a StateGate on the :status attribute with states of :draft, :pending, :published & :archived.

class Post < ActiveRecord::Base
  include StateGate

  state_gate :status do
    state :draft,     transitions_to: :pending
    state :pending,   transitions_to: [:published, :archived], human: 'Pending Approval'
    state :published, transitions_to: :archived
    state :archived
  end
end

...configuration options

...class methods

...scope methods

...instance methods


//: # "##### RSP //: # "###################################################" //: # "##### HEADER #####" //: # "###################################################"

Current Status

ruby 4.0

ruby 3.0 ruby 3.1 ruby 3.2 ruby 3.3 ruby 3.4

ruby 2.6 ruby 2.7

100% Test Coverage License: MIT Gem Version

Index


Simple State Management for ActiveRecord!

The state, the whole state and nothing but the state!

Why StateGate?

StateGate is built on the belief that ActiveRecord is already great at managing state via validations. We provide the 'gate' to ensure valid transitions, without the overhead of event DSLs and complex guard logic.

Feature Description
Strict States only defined states can be set
Strict Transitions only defined transitions are allowed
No Guarding ActiveRecord Validations are better than guard clauses
No Eventing simply change state within normal model methods
Fast Fail exceptions are raised before accessing the DB or triggering any callbacks
No Ambiguous Result state changes succeed, or raise an exception - no need to check the response
Easy Testing built-in matchers for RSpec & Minitest make testing much easier
Simple to Implement with a simple DSL, StateGate is intuitive and easy to use

Requirements

  • Ruby 2.6+
  • ActiveRecord 5.0+

Installation

Add this line to your Gemfile:

gem 'state_gate'


Summary

A quick list of StateGate's creation, configuration, class & instance methods. Each method links to a more in-depth explanation within the Wiki.

...creation

Creating a StateGate on the :status attribute with states of :draft, :pending, :published & :archived.

class Post < ActiveRecord::Base
  include StateGate

  state_gate :status do
    state :draft,     transitions_to: :pending
    state :pending,   transitions_to: [:published, :archived], human: 'Pending Approval'
    state :published, transitions_to: :archived
    state :archived
  end
end

...configuration options

...class methods

...scope methods

...instance methods


Testing with Minitest


Testing with RSpec


Contributing

In all cases please respect our Contributor Code of Conduct.

Security issues

If you have found a security related issue, please follow our Security Policy.

Reporting issues

Please try to answer the following questions in your bug report:

  • What did you do?
  • What did you expect to happen?
  • What happened instead?

Make sure to include as much relevant information as possible, including:

  • Ruby version.
  • StateGate version.
  • ActiveRecord version.
  • OS version.
  • The steps needed to replicate the issue.
  • Any stack traces you have are very valuable.

Pull Requests

We encourage contributions via GitHub pull requests.

Our Developer Guide details how to fork the project; get it running locally; run the tests; check the documentation; check your style; and submit a pull request.


Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

Read the full details in our Contributor Code of Conduct.


License

The MIT License (MIT)

Copyright (c) 2020 CodeMeister

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. EC TEST HELPERS #####" //: # "###################################################"

Testing with RSpec


Testing with RSpec


Contributing

In all cases please respect our Contributor Code of Conduct.

Security issues

If you have found a security related issue, please follow our Security Policy.

Reporting issues

Please try to answer the following questions in your bug report:

  • What did you do?
  • What did you expect to happen?
  • What happened instead?

Make sure to include as much relevant information as possible, including:

  • Ruby version.
  • StateGate version.
  • ActiveRecord version.
  • OS version.
  • The steps needed to replicate the issue.
  • Any stack traces you have are very valuable.

Pull Requests

We encourage contributions via GitHub pull requests.

Our Developer Guide details how to fork the project; get it running locally; run the tests; check the documentation; check your style; and submit a pull request.


Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

Read the full details in our Contributor Code of Conduct.


License

The MIT License (MIT)

Copyright (c) 2020 CodeMeister

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages