Jacaranda

Generates helper methods based on your model validations creating common methods and scopes.

Installation

Add this line to your application's Gemfile:

gem 'jacaranda'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jacaranda

Usage

Basic

Simply add the following line after the validations:

acts_as_jacaranda

like that

class Post < ActiveRecord::Base
  validates :status, inclusion: { in: %w{published unpublished draft} }
  acts_as_jacaranda
end

Now your model Post received some powers, we see them.

Predicate methods

Ask @post if it was published with @post.published? or it is a draft with @post.draft?.

Scopes

Find the posts based on column status using the generated scopes like Post.published e Post.draft.

Scoped

Perhaps model has 2 validations of inclusion that have valid values repeated

class Post < ActiveRecord::Base
  validates :status, inclusion: { in: %w{published unpublished draft} }
  validates :kind, inclusion: { in: %w{report unpublished draft} }
  acts_as_jacaranda
end

in this case use Jacaranda with the param scoped:

acts_as_jacaranda scoped: true

which will generate methods based on column like #unpublished_status? and #unpublished_kind?.

Versioning

Jacaranda follow the Semantic Versioning.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request