Class: Bullet::ActionController

Inherits:
Object
  • Object
show all
Defined in:
lib/bullet/action_controller2.rb

Class Method Summary collapse

Class Method Details

.enableObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bullet/action_controller2.rb', line 3

def self.enable
  require 'action_controller'
  case Rails.version
  when /^2.3/  
    ::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
  when /^2.[2|1]/
    ::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"] and response.headers["type"].include? 'text/html' and response.body =~ %r{<html.*</html>}m
            response.body <<= Bullet.gather_inline_notifications
            response.headers["Content-Length"] = response.body.length.to_s
          end
        
          Bullet.perform_bullet_out_of_channel_notifications
        end
        Bullet.end_request
        response
      end
    end
  else
    puts "Gem Bullet: Unsupported rails version"
  end
end