{"id":19319735,"url":"https://github.com/hyperoslo/gamification","last_synced_at":"2025-04-22T17:32:12.717Z","repository":{"id":14848306,"uuid":"17571397","full_name":"hyperoslo/gamification","owner":"hyperoslo","description":"Gamification is a collection of models for Ruby on Rails that allows you to make anything a game","archived":false,"fork":false,"pushed_at":"2019-05-20T21:10:55.000Z","size":113,"stargazers_count":55,"open_issues_count":2,"forks_count":12,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-10-13T18:59:49.260Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperoslo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-09T19:07:22.000Z","updated_at":"2024-09-05T17:14:20.000Z","dependencies_parsed_at":"2022-09-23T23:50:36.823Z","dependency_job_id":null,"html_url":"https://github.com/hyperoslo/gamification","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Fgamification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Fgamification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Fgamification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Fgamification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperoslo","download_url":"https://codeload.github.com/hyperoslo/gamification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223902211,"owners_count":17222330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T01:25:05.443Z","updated_at":"2024-11-10T01:25:06.008Z","avatar_url":"https://github.com/hyperoslo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gamification\n\n[![Gem Version](https://img.shields.io/gem/v/gamification.svg?style=flat)](https://rubygems.org/gems/gamification)\n[![Build Status](https://img.shields.io/travis/hyperoslo/gamification.svg?style=flat)](https://travis-ci.org/hyperoslo/gamification)\n[![Dependency Status](https://img.shields.io/gemnasium/hyperoslo/gamification.svg?style=flat)](https://gemnasium.com/hyperoslo/gamification)\n[![Code Climate](https://img.shields.io/codeclimate/github/hyperoslo/gamification.svg?style=flat)](https://codeclimate.com/github/hyperoslo/gamification)\n[![Coverage Status](https://img.shields.io/coveralls/hyperoslo/gamification.svg?style=flat)](https://coveralls.io/r/hyperoslo/gamification)\n\nGamification is a collection of models for Ruby on Rails that allows you to make anything a game.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'gamification'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install gamification\n\nInstall and run the migrations:\n\n    $ rake gamification:install:migrations\n    $ rake db:migrate\n\n## Usage\n\nGamification consists of goals and rewards. A goal represents something that someone can do,\nand a reward represents someone doing that thing. Simple. What your goals are and who you will\nbe rewarding is up to you.\n\nFor example, imagine that you want to reward your users for reading articles on your site.\n\n```ruby\n# app/models/user.rb\nclass User \u003c ActiveRecord::Base\n  rewardable\nend\n\n# app/models/article.rb\nclass Article \u003c ActiveRecord::Base\n  rewarding\nend\n```\n\n`rewardable` declares that your users are eligible to receive rewards, whereas `rewarding`\ndeclares that your articles have a reward.\n\n### Rewardable\n\nRewardable models get a `has_many` relation to `Gamification::Reward`:\n\n```ruby\nuser = User.first\nuser.rewards # =\u003e [\u003cReward\u003e, \u003cReward\u003e]\n```\n\n### Rewarding\n\nRewarding models get a `has_many` relation to `Gamification::Goal`:\n\n```ruby\narticle = Article.first\narticle.goals # =\u003e [\u003cGoal\u003e, \u003cGoal\u003e]\n```\n\n### Medals\n\nGoals can have medals. Medals are a nice way to make someone feel extra special. They can\nhave a name, a description and an image. When a user completes a goal that has a medal,\nthey will receive that medal:\n\n```ruby\nuser = User.first\ngoal = Gamification::Goal.create\n\ngoal.create_medal do |medal|\n  medal.name = 'Special Medal'\n  medal.description = 'You are special! In a good way!'\nend\n\ngoal.complete_for user\n\nuser.medals # =\u003e [\u003cMedal\u003e]\n```\n\n### Awarding rewards\n\nSince goals can be anything, it's up to you to write the logic for awarding them. We\nrecommend using observers so you can keep it nice and isolated.\n\nHere's an observer that rewards a user for answering a question:\n\n```ruby\n# app/models/answer_observer.rb\nclass AnswerObserver \u003c ActiveRecord::Observer\n  observe Answer\n\n  def after_create(answer)\n    answer.question.goals.each do |goal|\n      goal.complete_for answer.user\n    end\n  end\nend\n```\n\nWe like to use rewards for easter eggs. For example, here's an observer that\nrewards a user for logging in thrice:\n\n```ruby\n# app/easter_eggs/hattrick_observer.rb\nclass HattrickObserver \u003c ActiveRecord::Observer\n  observe User\n\n  def after_save(user)\n    if eligible? user\n      goal.complete_for user\n    end\n  end\n\n  private\n\n  def eligible?(user)\n    user.sign_in_count == 3\n  end\n\n  def goal\n    Goal.hattrick\n  end\nend\n```\n\nSome things are more difficult to reward, though. In our example, you can't really tell whether\na user has read an article. You'll just have to trust them, and make a button that they can\nclick to confirm that they've read it:\n\n```\n# app/views/articles/_article.html.erb\n\u003c%= render @article %\u003e\n\u003c%= reward current_user, for: @article %\u003e\n```\n\n### Presenting rewards\n\nRewards are no good if you don't know about them, though, and so we've made a pretty sweet\nhelper for presenting rewards to your users when they get them. It's sort of like in Call\nof Duty, except without Activision breathing down your neck and making you churn out the\nsame title every year.\n\n```\n# app/views/layouts/application.html.erb\n\u003c%= present_rewards for: current_user %\u003e\n```\n\n## Configuration\n\nMedals have images, and Gamification uses [CarrierWave](https://github.com/carrierwaveuploader/carrierwave)\nto upload them. It defaults to saving images to disk, but if you'd rather save them to the\ncloud you'll have to configure it:\n\n```ruby\n# config/initializers/carrierwave.rb\nCarrierWave.configure do |config|\n  storage :fog\nend\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Credits\n\nHyper made this. We're a digital communications agency with a passion for good code,\nand if you're using Gamification we probably want to hire you.\n\n## License\n\nGamification is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperoslo%2Fgamification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperoslo%2Fgamification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperoslo%2Fgamification/lists"}