Giter Site home page Giter Site logo

kortirso / kudos Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 39 KB

Achievements engine for Rails application similar to World of Warcraft achievements system

License: MIT License

Ruby 73.74% HTML 24.30% JavaScript 0.23% CSS 1.73%
achievements reputation-system ruby-on-rails

kudos's Introduction

Kudos

Reputation engine for Rails application similar to World of Warcraft achievements system.

Installation

Add this line to your application's Gemfile:

gem 'kudos'

And then for generating migration and models execute:

$ bundle install
$ rails g kudos:active_record
$ rails db:migrate

If you would like to attach achievements not to User model, run instead

$ rails g kudos:active_record ModelName

Сonfiguration

class User < ApplicationRecord
  include Kudos::Achievementable
  ...
end

Generating achievements

Achievements database records

general_group = Kudos::AchievementGroup.create(name: { en: 'General' })

Kudos::Achievement.create(
  award_name: 'fantasy_team_create',
  points: 5,
  kudos_achievement_group: general_group
)

Describe award rules

For one rank achievements conditions for awarding can be defined like

class Achievement < Kudos::Achievement
  award_for :fantasy_team_create do |achievements, user|
    achievement = achievements.first
    user.award(achievement: achievement) unless user.awarded?(achievement: achievement)
  end
end

For multi-rank achievements conditions for awarding can be defined like

class Achievement < Kudos::Achievement
  award_for :lineup_points do |achievements, lineup|
    user = lineup.user
    achievements.each do |achievement|
      if !user.awarded?(achievement: achievement) && lineup.points >= (achievement.rank * 10)
        user.award(achievement: achievement)
      end
    end
  end
end

Usage

For awarding user just call this code in callback or by any event generator

Achievement.award(:fantasy_team_create, user)

License

The gem is available as open source under the terms of the MIT License.

kudos's People

Contributors

kortirso avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.