Module: DeclarativePolicy::PreferredScope

Included in:
DeclarativePolicy
Defined in:
lib/declarative_policy/preferred_scope.rb

Constant Summary collapse

PREFERRED_SCOPE_KEY =
:"DeclarativePolicy.preferred_scope"

Instance Method Summary collapse

Instance Method Details

#preferred_scopeObject


14
15
16
# File 'lib/declarative_policy/preferred_scope.rb', line 14

def preferred_scope
  Thread.current[PREFERRED_SCOPE_KEY]
end

#preferred_scope=(scope) ⇒ Object


26
27
28
# File 'lib/declarative_policy/preferred_scope.rb', line 26

def preferred_scope=(scope)
  Thread.current[PREFERRED_SCOPE_KEY] = scope
end

#subject_scope(&block) ⇒ Object


22
23
24
# File 'lib/declarative_policy/preferred_scope.rb', line 22

def subject_scope(&block)
  with_preferred_scope(:subject, &block)
end

#user_scope(&block) ⇒ Object


18
19
20
# File 'lib/declarative_policy/preferred_scope.rb', line 18

def user_scope(&block)
  with_preferred_scope(:user, &block)
end

#with_preferred_scope(scope) ⇒ Object


7
8
9
10
11
12
# File 'lib/declarative_policy/preferred_scope.rb', line 7

def with_preferred_scope(scope)
  Thread.current[PREFERRED_SCOPE_KEY], old_scope = scope, Thread.current[PREFERRED_SCOPE_KEY]
  yield
ensure
  Thread.current[PREFERRED_SCOPE_KEY] = old_scope
end