Sha256: 0fdb100a60b448fc9929b260ff3ebaae516f88a36a5133d60158c8b0b6adbf35

Contents?: true

Size: 624 Bytes

Versions: 4

Compression:

Stored size: 624 Bytes

Contents

module Thoth
  module Rails
    module ControllerContext

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

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

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

if defined?(::ActionController)
  ::ActiveSupport.on_load(:action_controller) { include Thoth::Rails::ControllerContext }
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thoth-0.0.6 lib/thoth/rails/controller_context.rb
thoth-0.0.5 lib/thoth/rails/controller_context.rb
thoth-0.0.3 lib/thoth/rails/controller_context.rb
thoth-0.0.2 lib/thoth/rails/controller_context.rb