Module: Thoth::Rails::ControllerContext

Defined in:
lib/thoth/rails/controller_context.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/thoth/rails/controller_context.rb', line 5

def self.included(base)
  base.around_action(:set_thoth_request_context)
end

Instance Method Details

#set_thoth_request_contextObject



9
10
11
12
13
# File 'lib/thoth/rails/controller_context.rb', line 9

def set_thoth_request_context
  Thoth.context = Thoth.context.merge(thoth_request_context)
  yield
  Thoth.clear_context!
end

#thoth_request_contextObject



15
16
17
18
19
# File 'lib/thoth/rails/controller_context.rb', line 15

def thoth_request_context
  context = params.to_h
  context[:current_user] = current_user.try(:id) if defined?(current_user)
  context
end