Class: Group

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/group.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_retrieval_methods(classname) ⇒ Object

we can’t has_many through the polymorphic permission relationship, so this is called from has_groups and for eg. Page, it defines: Permission.for_pages named_scope Group.page_permissions => set of permission objects Group.pages => set of page objects



69
70
71
72
73
74
# File 'app/models/group.rb', line 69

def self.define_retrieval_methods(classname)
  type_scope = "for_#{classname.downcase.pluralize}".intern
  Permission.send :named_scope, type_scope, :conditions => { :permitted_type => classname }
  define_method("#{classname.downcase}_permissions") { self.permissions.send type_scope }
  define_method("#{classname.downcase.pluralize}") { self.send("#{classname.to_s.downcase}_permissions".intern).map(&:permitted) }
end

Instance Method Details

#admit(reader) ⇒ Object



51
52
53
# File 'app/models/group.rb', line 51

def admit(reader)
  self.readers << reader
end

#membership_for(reader) ⇒ Object



59
60
61
# File 'app/models/group.rb', line 59

def membership_for(reader)
  self.memberships.for(reader).first
end

#permission_for(object) ⇒ Object



55
56
57
# File 'app/models/group.rb', line 55

def permission_for(object)
  self.permissions.for(object).first
end

#send_welcome_to(reader) ⇒ Object



44
45
46
47
48
49
# File 'app/models/group.rb', line 44

def send_welcome_to(reader)
  if reader.activated?                                        # welcomes will be triggered again on activation
    message = messages.for_function('group_welcome').first    # only if a group_welcome message exists *belonging to this group*
    message.deliver_to(reader) if message                     # (the belonging also allows us to mention the group in the message)
  end
end

#urlObject



40
41
42
# File 'app/models/group.rb', line 40

def url
  homepage.url if homepage
end