Module: Achievements::AchievementsEngine::IncludeClassMethods
- Defined in:
- lib/achievements/achievements_engine.rb
Instance Method Summary collapse
-
#achieve(context, agent_id, name) ⇒ Object
Trigger a bound achievement method.
-
#achievement(context, name, threshold) ⇒ Object
Binds an achievement with a specific counter threshold.
-
#achievements(object_array) ⇒ Object
Alternately, bind an entire array of achievement objects.
- #achieves(context_name_array) ⇒ Object
-
#engine ⇒ Object
Convenience method for accessing the current engine instance directly.
-
#make_engine(contexts) ⇒ Object
Instantiates the AchievementEngine and sets the contexts, which instantiate context specific counters.
-
#redis ⇒ Object
Convenienve method for accessing redis instance.
Instance Method Details
#achieve(context, agent_id, name) ⇒ Object
Trigger a bound achievement method. Since this is a class level method, you must include the agent id along with the method call
trigger agent_id, context, name
64 65 66 |
# File 'lib/achievements/achievements_engine.rb', line 64 def achieve(context, agent_id, name) @engine.achieve context, agent_id, name end |
#achievement(context, name, threshold) ⇒ Object
Binds an achievement with a specific counter threshold. Use as many as you’d like.
bind :context, :name, threshold
38 39 40 41 |
# File 'lib/achievements/achievements_engine.rb', line 38 def achievement(context, name, threshold) make_engine(context) if !@engine @engine.achievement(context,name,threshold) end |
#achievements(object_array) ⇒ Object
Alternately, bind an entire array of achievement objects. To use this, achievements must respond to the context, name, and threshold methods.
For example, when using with rails:
bind_all Achievement.all
51 52 53 54 55 56 |
# File 'lib/achievements/achievements_engine.rb', line 51 def achievements(object_array) object_array.each do |object| make_engine(context) if !@engine @engine.achievement object.context, object.name, object.threshold end end |
#achieves(context_name_array) ⇒ Object
68 69 70 71 72 |
# File 'lib/achievements/achievements_engine.rb', line 68 def achieves(context_name_array) context_name_array.each do |cna| Achievements.engine.achieve cna[0], @id, cna[1] end end |
#engine ⇒ Object
Convenience method for accessing the current engine instance directly
24 25 26 |
# File 'lib/achievements/achievements_engine.rb', line 24 def engine @engine end |
#make_engine(contexts) ⇒ Object
Instantiates the AchievementEngine and sets the contexts, which instantiate context specific counters. Use only once.
make_engine [:context1,:context2]
18 19 20 21 |
# File 'lib/achievements/achievements_engine.rb', line 18 def make_engine(contexts) @redis = Achievements.redis @engine = Engine.new(@redis) end |
#redis ⇒ Object
Convenienve method for accessing redis instance
29 30 31 |
# File 'lib/achievements/achievements_engine.rb', line 29 def redis @redis end |