Sha256: 934c8d28dba4a47c98112bada2b3edc9aa38849952e29707308bd46e12752c51

Contents?: true

Size: 1020 Bytes

Versions: 4

Compression:

Stored size: 1020 Bytes

Contents

module StrongPresenter
  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
          (StrongPresenter::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

4 entries across 4 versions & 1 rubygems

Version Path
strong_presenter-0.2.2 lib/strong_presenter/view_context/build_strategy.rb
strong_presenter-0.2.1 lib/strong_presenter/view_context/build_strategy.rb
strong_presenter-0.2.0 lib/strong_presenter/view_context/build_strategy.rb
strong_presenter-0.1.0 lib/strong_presenter/view_context/build_strategy.rb