Class: Socializer::Group
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Socializer::Group
- Extended by:
- Enumerize
- Includes:
- ObjectTypeBase
- Defined in:
- app/models/socializer/group.rb
Class Method Summary collapse
- .joinable ⇒ Object
- .private ⇒ Object
-
.public ⇒ Object
Class Methods.
- .restricted ⇒ Object
Instance Method Summary collapse
-
#author ⇒ Object
Instance Methods.
- #invite(person) ⇒ Object
- #join(person) ⇒ Object
- #leave(person) ⇒ Object
- #member?(person) ⇒ Boolean
- #members ⇒ Object
Methods included from ObjectTypeBase
Class Method Details
.joinable ⇒ Object
42 43 44 |
# File 'app/models/socializer/group.rb', line 42 def self.joinable Group.with_privacy_level(:public, :restricted) end |
.private ⇒ Object
38 39 40 |
# File 'app/models/socializer/group.rb', line 38 def self.private Group.with_privacy_level(:private) end |
.public ⇒ Object
Class Methods
30 31 32 |
# File 'app/models/socializer/group.rb', line 30 def self.public Group.with_privacy_level(:public) end |
.restricted ⇒ Object
34 35 36 |
# File 'app/models/socializer/group.rb', line 34 def self.restricted Group.with_privacy_level(:restricted) end |
Instance Method Details
#author ⇒ Object
Instance Methods
47 48 49 |
# File 'app/models/socializer/group.rb', line 47 def @author ||= .activitable end |
#invite(person) ⇒ Object
69 70 71 72 73 74 |
# File 'app/models/socializer/group.rb', line 69 def invite(person) @membership = person.memberships.build(group_id: id) @membership.active = false @membership.save end |
#join(person) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/socializer/group.rb', line 55 def join(person) @membership = person.memberships.build(group_id: id) if privacy_level.public? @membership.active = true elsif privacy_level.restricted? @membership.active = false else fail 'Cannot self-join a private group, you need to be invited' end @membership.save end |
#leave(person) ⇒ Object
76 77 78 79 |
# File 'app/models/socializer/group.rb', line 76 def leave(person) @membership = person.memberships.find_by(group_id: id) @membership.destroy end |
#member?(person) ⇒ Boolean
81 82 83 |
# File 'app/models/socializer/group.rb', line 81 def member?(person) person.memberships.find_by(group_id: id).present? end |
#members ⇒ Object
51 52 53 |
# File 'app/models/socializer/group.rb', line 51 def members @members ||= activity_members.map { |em| em.activitable } end |