Drafteable is a super simple and opinionated ActiveRecord model draft behavior encapsulation:
A drafteable model should:
- Provide a boolean field as a flag for its draft status.
- Provide methods to check draft or published status.
- Provide methods to change draft or published status.
Right now, this gem provides the last two points. You should generate the appropriate migration to add a draft column. Something like:
add_column :posts, :draft, :boolean, default: false
Installation
Add this line to your application's Gemfile:
gem 'drafteable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install drafteable
Usage
On your ActiveRecord model add
acts_as_drafteable
Then you get published?
, draft?
(for checking the state) and publish!
,
draft!
(for changing the status).
Note that calling draft! will save the model skipping validations.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
You've got test under spec/ and bundle install
should take care of
all gem dependencies for development.
TODO
- Write generator to create migration with draft field on model.