https://github.com/grimen/has_status
Rails: The missing status/enum field helpers for ActiveRecord.
https://github.com/grimen/has_status
Last synced: 3 months ago
JSON representation
Rails: The missing status/enum field helpers for ActiveRecord.
- Host: GitHub
- URL: https://github.com/grimen/has_status
- Owner: grimen
- License: mit
- Created: 2009-02-25T04:02:14.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2009-05-17T06:08:02.000Z (about 16 years ago)
- Last Synced: 2025-01-12T06:11:02.035Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 93.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: MIT-LICENSE
Awesome Lists containing this project
README
h1. HAS_STATUS
_The missing status/enum field helpers for ActiveRecord._
h2. Installation
sudo gem install grimen-has_statush2. Usage
In your model:
class Post < ActiveRecord:Base
has_status :publish_status, [:draft, :published, :some_status], :default => :published
has_status :priority, [:important, :no_priority], :labels => {:important => 'Important!', :no_priority => I18n.t('statuses.priority.low')}
end...gives:
@post.draft? # => @post == :draft, @post == 'draft'
@post.draft! # => @post = :draft
@post.published? # => @post == :published, @post == 'published'
@post.published! # => @post = :published
@post.has_publish_status?(:hello) # => @post == :hello, @post == 'hello'
@post.set_publish_status!(:hello) # => @post = :hello
@post = :draft
@post.next_publish_status! # => @post = :published
@post = :draft
@post.previous_publish_status! # => @post = :some_status
@post.reset_published_status! # = @post = :published
@post.publish_statuses_for_select # = [['Important!', 'important], ...]
Post::PUBLISH_STATUSES # => [:draft, :published, :some_status]
Post::DEFAULT_PUBLISH_STATUS # => :publishedh2. More...?
Things that passed my mind:
* Implement named scopes, or finder methods.
* Fix the :default option to work on initialize, now disabled.h2. License
Copyright (c) 2009 Jonas Grimfelt, released under the MIT-license.