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

etat

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

etat

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Etat

Etat is a minimalistic gem to help you (me, for now) manage some states in your app. It is built for Rails 4 and assumes the use of ActiveRecord 4. See the 'usage' section for more.

Etat means "State" in French.

Installation

Add this line to your application's Gemfile:

gem 'etat'

And then execute:

$ bundle

Usage

class MyModel < ActiveRecord::Base
  has_states :draft, :published, :deleted
  event :publish do
    # some code to happen on publish...
    self.state = :publish
    self.save!
  end
end

Etat will generate a few methods and scopes that will help you: MyModel.states will give you an array of the states. # [:draft, :published, :deleted] MyModel.all_published: scope that will return all records with that state (and equivalents for each states). MyModel.all_but_published: scope that will return all records except the ones with that state (and equivalents for each states). my_model_instance.state: it will return the current state, as a symbol, always. my_model_instance.published?: boolean. Will tell you if current record has that state or not (and equivalents for each states).

Contributing

  1. Fork it
  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 new Pull Request

FAQs

Package last updated on 02 Sep 2013

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