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
20
21
22
23
24
# File 'lib/thoth/rails/controller_context.rb', line 15

def thoth_request_context
  #>= Rails 4.2
  if ::Rails::VERSION::MAJOR >= 5 || (::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR >= 2)
    context = params.to_unsafe_h
  else
    context = params.to_h
  end
  context[:current_user] = current_user.try(:id) if defined?(current_user)
  context
end