Module: Badgeable::Adapters::MongoidAdapter

Defined in:
lib/badgeable/adapters/mongoid_adapter.rb

Class Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



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

def self.included(receiver)
  receiver.class_eval do
    embeds_many :badgings
  end
  
  ::Badging.class_eval %Q{
    embedded_in :#{receiver.to_s.underscore}, :inverse_of => :badgings
    def receiver
      #{receiver.to_s.underscore}
    end
  }
  
  ::Badge.class_eval %Q{
    def recipients
      #{receiver}.where("badgings.badge_id" => id)
    end
  }
  receiver.send(:include, InstanceMethods)
end