Skip to content
This provides achievement features for rails app.
Ruby JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.markdown
Rakefile
achievable.gemspec

README.markdown

Achievable

This provides achievement features for rails app.

Installation

To install Achievable, simply install the gem:

gem install achievable

Run generator to generate config information in application.rb, migration file achievable_migration, and model files achievement.rb and achieving.rb

rails g achievable MODEL

MODEL here is the achiever, model that receives achievement, for example: user. It will insert include Achievable::Achiever to User class.

Configuration for Resque

Check out resque

Achievable also provides resque functionality. The queue name is :achievable. Enable or disable resque in config/application.rb:

config.achievable.resque_enable = false

Usage

Specify which model is used for the achiever, take user for example:

class User < ActiveRecord::Base
  include Achievable::Achiever
  has_many :posts
end

Specify which column to check for achievement of in a model, the name of the achievement, receiver of achievement and condition in which achiever has to meet. If receiver is not set, then the model itself is the receiver.

class User < ActiveRecord::Base
  ...
  achievable :image_url,  "first_time_edit_avatar"
  ...
end

class Post < ActiveRecord::Base
  ...
  achievable :description,  "first_time_edit_description", :receiver => :user
  ...
end

class User < ActiveRecord::Base
  ... 
  achievable :tags_count, "tags_500_times", :condition => lambda { |u| u.tags_count >= 500 }
  ...
end

Or we can call achieve manually by:

user.achieve( name_of_achievement, :condition => lambda { ... } )

Note that achievement items have to be created FIRST!

TODO

Something went wrong with that request. Please try again.