Permalink
Browse files

Rules are being checked again. Little bug fix. :-p (fixes #2)

  • Loading branch information...
tute committed Apr 26, 2012
1 parent 5358486 commit 2d7aff15f8ee67851eb9c4ead7b05f5ca1672375
View
@@ -1,6 +1,6 @@
# Upgrading
-## to 0.6.0
+## to 0.6.1
<tt>MeritBadgeRules</tt>, <tt>MeritPointRules</tt> and <tt>MeritRankRules</tt>
are now namespaced into Merit module. Move and change:
@@ -13,6 +13,7 @@ app/models/merit_{badge|point|rank}_rules.rb -> app/models/merit/{badge|point|ra
- include Merit::{Badge|Point|Rank}Rules
+module Merit
+ class {Badge|Point|Rank}Rules
++ include Merit::{Badge|Point|Rank}RulesMethods
</pre>
## to 0.5.0
@@ -16,6 +16,8 @@
module Merit
class BadgeRules
+ include Merit::BadgeRulesMethods
+
def initialize
# If it creates user, grant badge
# Should be "current_user" after registration for badge to be granted.
@@ -5,6 +5,8 @@
module Merit
class PointRules
+ include Merit::PointRulesMethods
+
def initialize
# score 10, :on => [
# 'users#update'
@@ -10,6 +10,8 @@
module Merit
class RankRules
+ include Merit::RankRulesMethods
+
def initialize
# set_rank :level => 1, :to => Commiter.active do |commiter|
# commiter.repositories.count > 1 && commiter.followers >= 10
View
@@ -29,7 +29,7 @@ module Merit
#
# Luego chequea las condiciones sincronizadamente, o mediante un proceso en
# background, por ejemplo cada 5 minutos (Merit::BadgeRules#check_new_actions).
- class BadgeRules
+ module BadgeRulesMethods
# Define rule for granting badges
def grant_on(action, *args, &block)
options = args.extract_options!
@@ -2,7 +2,7 @@ module Merit
# Points are a simple integer value which are given to "meritable" resources
# according to rules in +app/models/merit_point_rules.rb+. They are given on
# actions-triggered.
- class PointRules
+ module PointRulesMethods
# Define rules on certaing actions for giving points
def score(points, *args, &block)
options = args.extract_options!
View
@@ -8,7 +8,7 @@ module Merit
# * :+to+ model or scope to check if new rankings apply
# * :+level_name+ attribute name (default is empty and results in 'level'
# attribute, if set it's appended like 'level_#{level_name}')
- class RankRules
+ module RankRulesMethods
# Populates +defined_rules+ hash with following hierarchy:
# defined_rules[ModelToRank] = { levels => blocks }
def set_rank(*args, &block)
View
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
s.homepage = "http://github.com/tute/merit"
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
- s.version = "0.6.0"
+ s.version = "0.6.1"
s.authors = ["Tute Costa"]
s.email = 'tutecosta@gmail.com'
s.add_dependency 'ambry'
@@ -16,14 +16,16 @@
module Merit
class BadgeRules
+ include Merit::BadgeRulesMethods
+
def initialize
# If it creates user, grant badge
# Should be "current_user" after registration for badge to be granted.
grant_on 'users#create', :badge => 'just-registered', :to => :itself
# If it has 10 comments, grant commenter-10 badge
grant_on 'comments#create', :badge => 'commenter', :level => 10 do |comment|
- comment.user.comments.count == 10
+ comment.user.comments.count >= 10
end
# If it has at least 10 votes, grant relevant-commenter badge
@@ -4,6 +4,8 @@
module Merit
class PointRules
+ include Merit::PointRulesMethods
+
def initialize
score 5, :to => :user, :on => [
'comments#vote'
@@ -10,6 +10,8 @@
module Merit
class RankRules
+ include Merit::RankRulesMethods
+
def initialize
# i stars for i chars name
(1..5).each do |i|
@@ -1,40 +0,0 @@
-# Create badges (Ambry)
-badge_id = 0
-
-# Rank badges (5 stars)
-(1..5).each do |i|
- Badge.create!(
- :id => (badge_id = badge_id+1),
- :name => 'stars',
- :level => i
- )
-end
-
-# Normal badges
-[
- {
- :id => (badge_id = badge_id+1),
- :name => 'commenter',
- :description => 'You\'ve participated good in our boards!',
- :level => 10
- }, {
- :id => (badge_id = badge_id+1),
- :name => 'commenter',
- :description => 'You\'ve participated great in our boards!',
- :level => 20
- }, {
- :id => (badge_id = badge_id+1),
- :name => 'relevant-commenter',
- :description => 'You\'ve received 5 votes on a comment.',
- :level => 5
- }, {
- :id => (badge_id = badge_id+1),
- :name => 'autobiographer',
- :description => 'You\'ve edited your name and it\'s above 4 characters! (?)'
- }, {
- :id => (badge_id = badge_id+1),
- :name => 'just-registered'
- }
-].each do |badge|
- Badge.create! badge
-end
@@ -5,4 +5,30 @@
# Define ORM. Could be :active_record (default) and :mongo_mapper
# config.orm = :active_record
-end
+end
+
+# Create application badges (uses https://github.com/norman/ambry)
+badge_id = 0
+[{
+ :id => (badge_id = badge_id+1),
+ :name => 'commenter',
+ :description => 'You\'ve participated good in our boards!',
+ :level => 10
+}, {
+ :id => (badge_id = badge_id+1),
+ :name => 'commenter',
+ :description => 'You\'ve participated great in our boards!'
+}, {
+ :id => (badge_id = badge_id+1),
+ :name => 'relevant-commenter',
+ :description => 'You\'ve received 5 votes on a comment.'
+}, {
+ :id => (badge_id = badge_id+1),
+ :name => 'autobiographer',
+ :description => 'You\'ve edited your name and it\'s above 4 characters! (?)'
+}, {
+ :id => (badge_id = badge_id+1),
+ :name => 'just-registered'
+}].each do |badge|
+ Badge.create! badge
+end

0 comments on commit 2d7aff1

Please sign in to comment.