Class: MechanizeProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/mechanize/progressbar/mechanize_progressbar.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mech, request, response) ⇒ MechanizeProgressBar



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 19

def initialize(mech, request, response)
  pbar_opts = mech.progressbar_option
  self.class.unregister(mech) if pbar_opts['reset!']

  _first_time = pbar_opts.empty?
  _unusual_response = response.code != '200'

  case
  when _first_time, _unusual_response
    @progressbar = nil
  else
    @progressbar = progressbar_new(pbar_opts, request, response)
  end

  if mech.log
    log_output = mech.log.instance_variable_get(:@logdev).dev
    pbar_output = @progressbar.instance_variable_get(:@out)
    @suppress_logger = true if log_output == pbar_output
  end

  @suppress_logger = pbar_opts[:suppress_logger] if pbar_opts.has_key?(:suppress_logger)
end

Class Method Details

.register(mech, pbar_opts) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 3

def self.register(mech, pbar_opts)
  unregister(mech)
  mech.progressbar_option.update(pbar_opts)

  reset_reservation = mech.progressbar_option['reserve!']
  mech.progressbar_option['reset!'] = reset_reservation
end

.unregister(mech) ⇒ Object



11
12
13
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 11

def self.unregister(mech)
  mech.progressbar_option.clear
end

.unregister_next_init(mech) ⇒ Object



15
16
17
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 15

def self.unregister_next_init(mech)
  mech.progressbar_option['reserve!'] = true
end

Instance Method Details

#finishObject



46
47
48
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 46

def finish
  @progressbar.finish if @progressbar
end

#inc(step) ⇒ Object



42
43
44
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 42

def inc(step)
  @progressbar.inc(step) if @progressbar
end

#suppress_logger?Boolean



50
51
52
# File 'lib/mechanize/progressbar/mechanize_progressbar.rb', line 50

def suppress_logger?
  @suppress_logger
end