Sha256: acc18b68b1ac8ffe93b59f7ec422ac2cf6d63004bf25956efb14ca090d64f292

Contents?: true

Size: 1002 Bytes

Versions: 11

Compression:

Stored size: 1002 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.new if defined?(ActionController::TestRequest)
          end
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
draper_new-3.0.0 lib/draper/view_context/build_strategy.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/draper-2.1.0/lib/draper/view_context/build_strategy.rb
draper-2.1.0 lib/draper/view_context/build_strategy.rb
draper-2.0.0 lib/draper/view_context/build_strategy.rb
draper-1.4.0 lib/draper/view_context/build_strategy.rb
draper-1.3.1 lib/draper/view_context/build_strategy.rb
draper-1.3.0 lib/draper/view_context/build_strategy.rb
draper-1.2.1 lib/draper/view_context/build_strategy.rb
draper-1.2.0 lib/draper/view_context/build_strategy.rb
jamesgolick-draper-1.1.1a lib/draper/view_context/build_strategy.rb
draper-1.1.0 lib/draper/view_context/build_strategy.rb