Module: Grant::Status

Includes:
MonoThread
Included in:
Grantor, SpecHelpers
Defined in:
lib/grant/status.rb

Defined Under Namespace

Modules: MonoThread, MultiThread

Class Method Summary collapse

Methods included from MonoThread

included

Class Method Details

.disable_grantObject

Getters/Setters



76
77
78
# File 'lib/grant/status.rb', line 76

def disable_grant
  self.is_grant_disabled = true
end

.do_as(user) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/grant/status.rb', line 110

def do_as(user)
  previous_user = Grant::User.current_user

  begin
    Grant::User.current_user = user
    result = yield if block_given?
  ensure
    Grant::User.current_user = previous_user
  end

  result
end

.enable_grantObject



80
81
82
# File 'lib/grant/status.rb', line 80

def enable_grant
  self.is_grant_disabled = false
end

.grant_disabled?Boolean

Status

Returns:

  • (Boolean)


65
66
67
# File 'lib/grant/status.rb', line 65

def grant_disabled?
  is_grant_disabled == true
end

.grant_enabled?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/grant/status.rb', line 69

def grant_enabled?
  ! grant_disabled?
end

.switch_to_monothreadObject



58
59
60
# File 'lib/grant/status.rb', line 58

def switch_to_monothread
  Grant::Status.send :include, MonoThread
end

.switch_to_multithreadObject

Change to global status (use ONLY in test env)



55
56
57
# File 'lib/grant/status.rb', line 55

def switch_to_multithread
  Grant::Status.send :include, MultiThread
end

.with_grantObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/grant/status.rb', line 97

def with_grant
  previously_disabled = grant_disabled?

  begin
    enable_grant
    result = yield if block_given?
  ensure
    disable_grant if previously_disabled
  end

  result
end

.without_grantObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/grant/status.rb', line 84

def without_grant
  previously_disabled = grant_disabled?

  begin
    disable_grant
    result = yield if block_given?
  ensure
    enable_grant unless previously_disabled
  end

  result
end