Module: Badgeable::Subject

Defined in:
lib/badgeable/subject.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



20
21
22
# File 'lib/badgeable/subject.rb', line 20

def self.included(receiver)
  Badgeable::Adapters.connect(receiver)
end

Instance Method Details

#award_badge(*args) ⇒ Object

Award a named badge to this object. If the badge doesn’t exist in the database already, it’s created by name.



5
6
7
8
9
10
# File 'lib/badgeable/subject.rb', line 5

def award_badge(*args)
  options = args.extract_options!
  name = args[0]
  badge = Badge.find_or_create_by_name(name, options)
  badges << badge unless has_badge?(badge)      
end

#has_badge?(badge) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/badgeable/subject.rb', line 12

def has_badge?(badge)
  badges.include?(badge)
end

#has_badge_named?(name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/badgeable/subject.rb', line 16

def has_badge_named?(name)
  badges.map(&:name).include?(name)
end