Sha256: eeb77d43a0b120c3bf73cdefdb7aef3fc4b338526e13777a178bb077cc0f3d7d

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 Bytes

Contents

module Draper
  module ViewContext
    # @private
    module BuildStrategy

      def self.new(name, &block)
        const_get(name.to_s.camelize).new(&block)
      end

      class Fast
        def initialize(&block)
          @view_context_class = Class.new(ActionView::Base, &block)
        end

        def call
          view_context_class.new
        end

        private

        attr_reader :view_context_class
      end

      class Full
        def initialize(&block)
          @block = block
        end

        def call
          controller.view_context.tap do |context|
            context.singleton_class.class_eval(&block) if block
          end
        end

        private

        attr_reader :block

        def controller
          (Draper::ViewContext.controller || ApplicationController.new).tap do |controller|
            controller.request ||= ActionController::TestRequest.create
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
draper-3.0.0.pre1 lib/draper/view_context/build_strategy.rb