Class: Pageflow::AccountMemberQuery::Scope

Inherits:
Pageflow::ApplicationQuery::Scope show all
Defined in:
app/models/pageflow/account_member_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, scope = User.all) ⇒ Scope

Create scope that can limit base scope to account members at or above a given role

Parameters:

  • account (Pageflow::Account)

    Required. Membership account to check.

  • scope (ActiveRecord::Relation<User>) (defaults to: User.all)

    Optional. Membership entity to check.



20
21
22
23
# File 'app/models/pageflow/account_member_query.rb', line 20

def initialize(, scope = User.all)
  @account = 
  @scope = scope
end

Instance Attribute Details

#accountPageflow::Account (readonly)

Account whose members we scope

Returns:



7
8
9
# File 'app/models/pageflow/account_member_query.rb', line 7

def 
  @account
end

#scopeActiveRecord::Relation<User> (readonly)

Base scope which is further scoped according to account role

Returns:

  • (ActiveRecord::Relation<User>)


11
12
13
# File 'app/models/pageflow/account_member_query.rb', line 11

def scope
  @scope
end

Instance Method Details

#with_role_at_least(role) ⇒ ActiveRecord::Relation<User>

Scope to those members from scope on account who have at least role

Parameters:

  • role (String)

    Required. Minimum role that we compare against.

Returns:

  • (ActiveRecord::Relation<User>)


31
32
33
34
# File 'app/models/pageflow/account_member_query.rb', line 31

def with_role_at_least(role)
  scope.joins((role))
       .where(membership_is_present)
end