Module: Achievable::Achiever
Instance Method Summary collapse
- #achieve(name, options = {}) ⇒ Object
- #achieved?(achievement) ⇒ Boolean
- #achieveit!(name, &block) ⇒ Object
Methods included from AchieveManager
Instance Method Details
#achieve(name, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/achievable/achiever.rb', line 11 def achieve(name, = {}) condition = [:condition] ? [:condition] : ( lambda { |u| true } ) if Achievable.resque_enable achieveit(name, &condition) else achieveit!(name, &condition) end end |
#achieved?(achievement) ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/achievable/achiever.rb', line 27 def achieved?(achievement) if achievement.is_a? String achievement = Achievement.find_by_name!(achievement) end achievements.include?(achievement) end |
#achieveit!(name, &block) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/achievable/achiever.rb', line 20 def achieveit!(name, &block) achievement = Achievement.find_by_name!(name) unless achieved?(achievement) achievement.achieve(self) if ( block_given? ? block.call(self) : true ) end end |