Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snm-enum-transition

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snm-enum-transition

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Gem Version

Snm::Enum::Transition

Active Record ENUM based state machine. Whether you can control enum transation from one state to another state. Suppose you have an user model and you want to once user has been rejected he can't be verified, You can achive this job easily using this library.

Installation

Add this line to your application's Gemfile:

gem "snm-enum-transition"

And then execute:

$ bundle

Or install it yourself as:

$ gem install snm-enum-transition

Usage


# You have an user model and you want to specify status transitions: initial to verified, initial to rejected and rejected to initial


class User
  include Snm::Enum::Transition

  enum status: {initial: 0, verified: 1, rejected: 2]

  # Specify (allow enum transition) column name, from and to
  snm_enum_transitions :status, :initial, [:verified, :rejected]
  snm_enum_transitions :status, [:rejected], [:initial]
end

user = User.create(status: :initial)


# IF user status is initial
user.verified! # Okay
user.rejected! # Okay

# IF user status is verified
user.rejected! # ActiveRecord::RecordInvalid: Validation failed: Status can't be changed from verified to rejected
user.initial! # ActiveRecord::RecordInvalid: Validation failed: Status can't be changed from verified to initial

# IF user status is rejected
user.initial! # Okay
user.verified! # ActiveRecord::RecordInvalid: Validation failed: Status can't be changed from rejected to verified

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/snmmaurya/snm-enum-transition. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc