Sha256: db424234480b3ae5e6b31351a124b3b61e2d63f1ba7cb83c389f101fd4df2163

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Draper
  module ViewContext
    def self.current_controller
      Thread.current[:current_controller] || ApplicationController.new
    end

    def self.current_controller=(controller)
      Thread.current[:current_controller] = controller
    end

    def self.current
      Thread.current[:current_view_context] ||= build_view_context
    end

    def self.current=(context)
      Thread.current[:current_view_context] = context
    end

    def view_context
      super.tap do |context|
        Draper::ViewContext.current = context
      end
    end

    private

    def self.build_view_context
      current_controller.view_context.tap do |context|
        context.instance_eval do
          def url_options
            ActionMailer::Base.default_url_options
          end
        end unless context.request
        if defined?(ActionController::TestRequest)
          context.controller.request ||= ActionController::TestRequest.new
          context.request            ||= context.controller.request
          context.params             ||= {}
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
draper-0.18.0 lib/draper/view_context.rb