Class: Pageflow::AccountMemberQuery::Scope

Inherits:
Object
  • Object
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.



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

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

Instance Attribute Details

#accountPageflow::Account (readonly)

Account whose members we scope

Returns:



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

def 
  @account
end

#scopeActiveRecord::Relation<User> (readonly)

Base scope which is further scoped according to account role

Returns:

  • (ActiveRecord::Relation<User>)


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

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>)


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

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