Class: Group
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Group
- Defined in:
- app/models/group.rb
Class Method Summary collapse
-
.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.
- .visible_to(reader = nil) ⇒ Object
Instance Method Summary collapse
- #admit(reader) ⇒ Object
- #filename ⇒ Object
- #members ⇒ Object
- #membership_for(reader) ⇒ Object
- #permission_for(object) ⇒ Object
- #send_welcome_to(reader) ⇒ Object
- #url ⇒ Object
- #visible_to?(reader = nil) ⇒ Boolean
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
116 117 118 119 120 121 122 123 124 |
# File 'app/models/group.rb', line 116 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..send type_scope } define_method("#{classname.downcase.pluralize}") { ids = self.send("#{classname.to_s.downcase}_permissions".intern).map(&:permitted_id) classname.constantize.find_these(ids) } end |
.visible_to(reader = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/group.rb', line 61 def self.visible_to(reader=nil) case Radiant.config['reader.directory_visibility'] when 'public' self.all when 'private' reader ? self.all : self.none when 'grouped' (reader && reader.is_grouped?) ? reader.groups : self.none else self.none end end |
Instance Method Details
#admit(reader) ⇒ Object
98 99 100 |
# File 'app/models/group.rb', line 98 def admit(reader) self.readers << reader end |
#filename ⇒ Object
86 87 88 |
# File 'app/models/group.rb', line 86 def filename name.downcase.gsub(/\W/, '_') end |
#members ⇒ Object
78 79 80 |
# File 'app/models/group.rb', line 78 def members readers end |
#membership_for(reader) ⇒ Object
106 107 108 |
# File 'app/models/group.rb', line 106 def membership_for(reader) self.memberships.for(reader).first end |
#permission_for(object) ⇒ Object
102 103 104 |
# File 'app/models/group.rb', line 102 def (object) self..for(object).first end |
#send_welcome_to(reader) ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/models/group.rb', line 90 def send_welcome_to(reader) if reader.activated? # welcomes are also triggered on activation if = Message.belonging_to(self).for_function('group_welcome').first # only if a group_welcome message exists *belonging to this group* .deliver_to(reader) end end end |
#url ⇒ Object
82 83 84 |
# File 'app/models/group.rb', line 82 def url homepage.url if homepage end |
#visible_to?(reader = nil) ⇒ Boolean
74 75 76 |
# File 'app/models/group.rb', line 74 def visible_to?(reader=nil) self.class.visible_to(reader).map(&:id).include? self.id end |