Module: Achievable::Achiever

Extended by:
ActiveSupport::Concern
Includes:
AchieveManager
Defined in:
lib/achievable/achiever.rb

Instance Method Summary collapse

Methods included from AchieveManager

#achieveit, perform

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, options = {})
  condition = options[:condition] ? options[:condition] : ( lambda { |u| true } )
  if Achievable.resque_enable
    achieveit(name, &condition)
  else
    achieveit!(name, &condition)
  end
end

#achieved?(achievement) ⇒ Boolean

Returns:

  • (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