merit 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +7 -7
- data/lib/merit/rules_badge.rb +4 -3
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -26,10 +26,10 @@ Define rules on +app/models/merit_badge_rules.rb+:
|
|
26
26
|
* :+badge+ for badge name
|
27
27
|
* :+level+ for badge level
|
28
28
|
* :+to+: method name over target_object which obtains user to badge.
|
29
|
-
* :+temporary+ (boolean): if the condition doesn't hold and the receiver had
|
30
|
-
the badge, it gets removed. +false+ by default (badges are kept forever).
|
31
29
|
* :+model_name+ (string): when controller's name differs from the model being
|
32
30
|
worked (like RegistrationsController for User model).
|
31
|
+
* :+temporary+ (boolean): if the condition doesn't hold and the receiver had
|
32
|
+
the badge, it gets removed. +false+ by default (badges are kept forever).
|
33
33
|
* &+block+
|
34
34
|
* empty (always grants)
|
35
35
|
* a block which evaluates to boolean (recieves target object as parameter)
|
@@ -117,11 +117,11 @@ Added +had_errors+ boolean attribute to +merit_actions+ table.
|
|
117
117
|
= Test application
|
118
118
|
|
119
119
|
To run the test application inside this gem follow:
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
120
|
+
cd test/dummy
|
121
|
+
rails g merit:install
|
122
|
+
rails g merit user
|
123
|
+
rake db:migrate ; rake db:seed
|
124
|
+
rails s
|
125
125
|
|
126
126
|
|
127
127
|
= To-do list
|
data/lib/merit/rules_badge.rb
CHANGED
@@ -35,15 +35,16 @@ module Merit
|
|
35
35
|
def grant_on(action, *args, &block)
|
36
36
|
options = args.extract_options!
|
37
37
|
|
38
|
+
actions = action.kind_of?(String) ? [action] : action
|
39
|
+
|
38
40
|
rule = Rule.new
|
39
41
|
rule.badge_name = options[:badge]
|
40
42
|
rule.level = options[:level]
|
41
43
|
rule.to = options[:to] || :action_user
|
42
44
|
rule.temporary = options[:temporary] || false
|
43
|
-
rule.model_name = options[:model_name] ||
|
45
|
+
rule.model_name = options[:model_name] || actions[0].split('#')[0]
|
44
46
|
rule.block = block
|
45
47
|
|
46
|
-
actions = action.kind_of?(String) ? [action] : action
|
47
48
|
actions.each do |action|
|
48
49
|
defined_rules[action] ||= []
|
49
50
|
defined_rules[action] << rule
|
@@ -62,4 +63,4 @@ module Merit
|
|
62
63
|
@defined_rules ||= {}
|
63
64
|
end
|
64
65
|
end
|
65
|
-
end
|
66
|
+
end
|