Class: Decidim::UserGroups::MemberMemberships

Inherits:
Rectify::Query
  • Object
show all
Defined in:
app/queries/decidim/user_groups/member_memberships.rb

Overview

Use this class to find the the members of the given user group with the “member” role. It returns memberships.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_group) ⇒ MemberMemberships

Initializes the class.

user_group - a UserGroup that needs to find its member users



18
19
20
# File 'app/queries/decidim/user_groups/member_memberships.rb', line 18

def initialize(user_group)
  @user_group = user_group
end

Class Method Details

.for(user_group) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

user_group - a UserGroup that needs to find its member users



11
12
13
# File 'app/queries/decidim/user_groups/member_memberships.rb', line 11

def self.for(user_group)
  new(user_group).query
end

Instance Method Details

#queryObject

Finds the member users of the user group.

Returns an ActiveRecord::Relation.



25
26
27
28
29
30
# File 'app/queries/decidim/user_groups/member_memberships.rb', line 25

def query
  user_group
    .memberships
    .includes(:user)
    .where(role: :member)
end