Skip to content

Commit

Permalink
Adhere to conventions more
Browse files Browse the repository at this point in the history
  • Loading branch information
aviav committed Aug 2, 2017
1 parent 592fc11 commit 610dad7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 5 additions & 6 deletions app/models/pageflow/account_member_query.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Pageflow
# Query accounts for members, e.g. based on role
class AccountMemberQuery < ApplicationQuery
class Scope < Scope
class Scope < ApplicationQuery::Scope
# Account whose members we scope
# @return {Pageflow::Account}
# @return [Pageflow::Account]
attr_reader :account

# Base scope which is further scoped according to account role
Expand All @@ -12,7 +13,7 @@ class Scope < Scope
# Create scope that can limit base scope to account members at
# or above a given role
#
# @param {Pageflow::Account} account
# @param [Pageflow::Account] account
# Required. Membership account to check.
# @param [ActiveRecord::Relation<User>] scope
# Optional. Membership entity to check.
Expand All @@ -24,7 +25,7 @@ def initialize(account, scope = User.all)
# Scope to those members from scope on account who have at least
# role
#
# @param {String} role
# @param [String] role
# Required. Minimum role that we compare against.
# @return [ActiveRecord::Relation<User>]
def with_role_at_least(role)
Expand All @@ -34,7 +35,6 @@ def with_role_at_least(role)

private

# @api private
def memberships_for_account_with_at_least_role(role)
options = {roles: Roles.at_least(role), account_id: account.id}

Expand All @@ -48,7 +48,6 @@ def memberships_for_account_with_at_least_role(role)
SQL
end

# @api private
def membership_is_present
'pageflow_account_memberships.entity_id IS NOT NULL'
end
Expand Down
9 changes: 5 additions & 4 deletions app/models/pageflow/account_role_query.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module Pageflow
# Query users for their role on accounts based on role
class AccountRoleQuery
# Create query that can be used for role comparisons
#
# @param {User} user
# @param [User] user
# Required. Membership user to check.
# @param {Pageflow::Account} account
# @param [Pageflow::Account] account
# Required. Membership entity to check.
def initialize(user, account)
@user = user
Expand All @@ -14,9 +15,9 @@ def initialize(user, account)
# Return true if there is a membership with at least role for
# user/account
#
# @param {String} role
# @param [String] role
# Required. Minimum role that we compare against.
# @return {Boolean}
# @return [Boolean]
def has_at_least_role?(role)
@user
.memberships
Expand Down
3 changes: 2 additions & 1 deletion app/models/pageflow/application_query.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Pageflow
# Abstraction layer for Pageflow's query interface
class ApplicationQuery
class Scope
protected

# @api protected
# @api private
def sanitize_sql(sql, interpolations)
ActiveRecord::Base.send(:sanitize_sql_array, [sql, interpolations])
end
Expand Down

0 comments on commit 610dad7

Please sign in to comment.