Sha256: 97fedbef123241492b6768c2d3e3bdf43a613234d4716e0e362b00a7b3f72438

Contents?: true

Size: 1.43 KB

Versions: 19

Compression:

Stored size: 1.43 KB

Contents

module PhantomJSProxy
  class PhantomJSControlPanel
    def initialize
      @start_time = Time.new
      @total_requests = 0
      @special_requests = Hash.new
      @special_requests.default = 0
    end

    attr_accessor :start_time
    
    attr_accessor :total_requests
    attr_accessor :route_requests
    attr_accessor :html_requests
    attr_accessor :picture_requests
    attr_accessor :special_requests
    
    def show
      add_special_request "@control_requests"
      
      resp = Rack::Response.new([], 200,   {
        'Content-Type' => 'text/html'
        }) { |r|
          r.write(load_html)
        }
      resp.finish
    end
    
    def add_request
      @total_requests = @total_requests+1
    end
    
    def add_special_request type
      @special_requests[type] = @special_requests[type]+1
    end
    
    private
    def load_html
      insert_value IO.read(CONTROL_PANEL)
    end
    
    def insert_value html
      info_data = ""
      info_data << create_entry("Running since", start_time.ctime)
      info_data << create_entry("Total requests", total_requests.to_s)
      special_requests.each { |key, value|
        info_data << create_entry(key, special_requests[key].to_s)
      }
      html["@control_panel_data"] = info_data
      
      html
    end
    
    def create_entry name, value
      "<div class='name'>#{name}:</div><div class='value' id='#{name}'>#{value}</div><div class='divider'></div>"
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
phantom_proxy-1.2.17 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.16 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.15 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.14 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.13 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.12 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.11 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.10 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.9 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.8 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.7 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.6 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.5 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.4 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.3 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.2 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.1 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.2.0 lib/phantom_proxy/phantomjs_control_panel.rb
phantom_proxy-1.1.0 lib/phantom_proxy/phantomjs_control_panel.rb