Class: Socializer::Group

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Enumerize
Includes:
ObjectTypeBase
Defined in:
app/models/socializer/group.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ObjectTypeBase

#guid

Class Method Details

.joinableObject



42
43
44
# File 'app/models/socializer/group.rb', line 42

def self.joinable
  Group.with_privacy_level(:public, :restricted)
end

.privateObject



38
39
40
# File 'app/models/socializer/group.rb', line 38

def self.private
  Group.with_privacy_level(:private)
end

.publicObject

Class Methods



30
31
32
# File 'app/models/socializer/group.rb', line 30

def self.public
  Group.with_privacy_level(:public)
end

.restrictedObject



34
35
36
# File 'app/models/socializer/group.rb', line 34

def self.restricted
  Group.with_privacy_level(:restricted)
end

Instance Method Details

#authorObject

Instance Methods



47
48
49
# File 'app/models/socializer/group.rb', line 47

def author
  @author ||= activity_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

Returns:

  • (Boolean)


81
82
83
# File 'app/models/socializer/group.rb', line 81

def member?(person)
  person.memberships.find_by(group_id: id).present?
end

#membersObject



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

def members
  @members ||= activity_members.map { |em| em.activitable }
end