module Thoth::Rails::ControllerContext

Public Class Methods

included(base) click to toggle source
# File lib/thoth/rails/controller_context.rb, line 5
def self.included(base)
  base.around_action(:set_thoth_request_context)
end

Public Instance Methods

set_thoth_request_context() { || ... } click to toggle source
# 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_context() click to toggle source
# 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