module DeclarativePolicy::PreferredScope

Constants

PREFERRED_SCOPE_KEY

Public Instance Methods

preferred_scope() click to toggle source
# File lib/declarative_policy/preferred_scope.rb, line 15
def preferred_scope
  Thread.current[PREFERRED_SCOPE_KEY]
end
preferred_scope=(scope) click to toggle source
# File lib/declarative_policy/preferred_scope.rb, line 27
def preferred_scope=(scope)
  Thread.current[PREFERRED_SCOPE_KEY] = scope
end
subject_scope(&block) click to toggle source
# File lib/declarative_policy/preferred_scope.rb, line 23
def subject_scope(&block)
  with_preferred_scope(:subject, &block)
end
user_scope(&block) click to toggle source
# File lib/declarative_policy/preferred_scope.rb, line 19
def user_scope(&block)
  with_preferred_scope(:user, &block)
end
with_preferred_scope(scope) { || ... } click to toggle source
# File lib/declarative_policy/preferred_scope.rb, line 7
def with_preferred_scope(scope)
  old_scope = Thread.current[PREFERRED_SCOPE_KEY]
  Thread.current[PREFERRED_SCOPE_KEY] = scope
  yield
ensure
  Thread.current[PREFERRED_SCOPE_KEY] = old_scope
end