Sha256: 7ec4caa7beb3aa4de639f8c65107a83b9e1754b6d6ee91cb5bf6ada6fe71142b

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

module Bullet
  class ActionController
    extend Dependency

    def self.enable
      require 'action_controller'
      if active_record23?
        ::ActionController::Dispatcher.middleware.use Bullet::Rack
        ::ActionController::Dispatcher.class_eval do
          class <<self
            alias_method :origin_reload_application, :reload_application
            def reload_application
              origin_reload_application
              Bullet.clear
            end
          end
        end
      elsif active_record21? || active_record22?
        ::ActionController::Dispatcher.class_eval do
          alias_method :origin_reload_application, :reload_application
          def reload_application
            origin_reload_application
            Bullet.clear
          end
        end

        ::ActionController::Base.class_eval do
          alias_method :origin_process, :process
          def process(request, response, method = :perform_action, *arguments)
            Bullet.start_request
            response = origin_process(request, response, method = :perform_action, *arguments)

            if Bullet.notification?
              if response.headers["type"] && response.headers["type"].include?('text/html') && response.body.include?("<html>")
                response.body <<= Bullet.gather_inline_notifications
                response.headers["Content-Length"] = response.body.length.to_s
              end

              Bullet.perform_out_of_channel_notifications
            end
            Bullet.end_request
            response
          end
        end
      else
        puts "Gem Bullet: Unsupported rails version"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bullet-4.2.0 lib/bullet/action_controller2.rb
bullet-4.1.6 lib/bullet/action_controller2.rb
bullet-4.1.5 lib/bullet/action_controller2.rb
bullet-4.1.4 lib/bullet/action_controller2.rb
bullet-4.1.3 lib/bullet/action_controller2.rb
bullet-4.1.2 lib/bullet/action_controller2.rb
bullet-4.1.1 lib/bullet/action_controller2.rb