Module: Achiever

Defined in:
lib/achiever/achiever.rb

Constant Summary collapse

ALL_ACHIEVEMENTS =
[]

Instance Method Summary collapse

Instance Method Details

#achieves(award, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/achiever/achiever.rb', line 5

def achieves(award, options={})
	ALL_ACHIEVEMENTS << award

	user = options[:for]

	class_eval <<-EOF
		after_save :award_#{award.to_s}?
		
		def award_#{award.to_s}?
			achievement 		= Achievements::#{award.to_s.camelize}.new :user => self.#{user}
			achievement.model	= self 	

			if achievement.award?
				achievement.save
			end
		end
		
	EOF
end