module Sand::Helpers

Public Instance Methods

authorize(user, record, query) click to toggle source
# File lib/sand/helpers.rb, line 9
def authorize(user, record, query)
  authorized!
  policy = Sand.policy!(user, record)
  unless policy.public_send(query)
    raise Sand::NotAuthorizedError.new(policy: policy, query: query, record: record) # rubocop:disable Metrics/LineLength, Style/RaiseArgs
  end
end
policy_scope(user, record) click to toggle source
# File lib/sand/helpers.rb, line 3
def policy_scope(user, record)
  scoped!
  scope = PolicyFinder.new(record).scope!
  scope.new(user, record).resolve if scope
end
skip_sand_authorization() click to toggle source
# File lib/sand/helpers.rb, line 17
def skip_sand_authorization
  authorized!
end
skip_sand_scoping() click to toggle source
# File lib/sand/helpers.rb, line 21
def skip_sand_scoping
  scoped!
end

Private Instance Methods

authorized!() click to toggle source
# File lib/sand/helpers.rb, line 27
def authorized!
  env['sand.authorized'] = true
end
scoped!() click to toggle source
# File lib/sand/helpers.rb, line 31
def scoped!
  env['sand.scoped'] = true
end