12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/attendable/acts_as_invitable.rb', line 12
def acts_as_invitable(name, options = {})
class_name = options[:class_name] || name.to_s.classify
attendable_class_name = options[:to]
table_name = class_name.tableize
has_many name, as: :invitable, dependent: :destroy, class_name: class_name
has_many attendable_class_name.tableize.to_sym, conditions: "#{table_name}.rsvp_status = 'attending'", through: name, source: :attendable, source_type: attendable_class_name
clazz = class_name.constantize
define_method "is_member?" do |attendable|
puts 'is member? ' + attendable.to_s
puts 'clazz: ' + clazz.to_s
clazz.where(invitee: self, attendable: attendable).count > 0
end
end
|