Sha256: 1005c011e9ceaadb41e674776a4e247faca15536ef63660671fe19f283adb107

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

module ActiveDecorator
  module ViewContext
    class << self
      def current
        Thread.current[:active_decorator_view_contexts].last
      end

      def push(view_context)
        Thread.current[:active_decorator_view_contexts] ||= []
        Thread.current[:active_decorator_view_contexts] << view_context
      end

      def pop
        Thread.current[:active_decorator_view_contexts].pop if Thread.current[:active_decorator_view_contexts]
      end
    end

    module Filter
      extend ActiveSupport::Concern

      included do
        if Rails::VERSION::MAJOR >= 4
          around_action do |controller, blk|
            begin
              ActiveDecorator::ViewContext.push controller.view_context
              blk.call
            ensure
              ActiveDecorator::ViewContext.pop
            end
          end
        else
          around_filter do |controller, blk|
            begin
              ActiveDecorator::ViewContext.push controller.view_context
              blk.call
            ensure
              ActiveDecorator::ViewContext.pop
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
active_decorator-0.7.1 lib/active_decorator/view_context.rb
active_decorator-0.7.0 lib/active_decorator/view_context.rb
active_decorator-0.6.0 lib/active_decorator/view_context.rb
lulalala_presenter-0.0.1 lib/active_decorator/view_context.rb
active_decorator-0.5.3 lib/active_decorator/view_context.rb
active_decorator-0.5.2 lib/active_decorator/view_context.rb
active_decorator-0.5.1 lib/active_decorator/view_context.rb
active_decorator-0.5.0 lib/active_decorator/view_context.rb