Module: Badgeable::Subject
- Defined in:
- lib/badgeable/subject.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#award_badge(*args) ⇒ Object
Award a named badge to this object.
- #has_badge?(badge) ⇒ Boolean
- #has_badge_named?(name) ⇒ Boolean
Class Method Details
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) = args. name = args[0] badge = Badge.find_or_create_by_name(name, ) badges << badge unless has_badge?(badge) end |
#has_badge?(badge) ⇒ Boolean
12 13 14 |
# File 'lib/badgeable/subject.rb', line 12 def has_badge?(badge) badges.include?(badge) end |
#has_badge_named?(name) ⇒ Boolean
16 17 18 |
# File 'lib/badgeable/subject.rb', line 16 def has_badge_named?(name) badges.map(&:name).include?(name) end |