| Class | WWW::Mechanize::History |
| In: |
lib/www/mechanize/history.rb
|
| Parent: | Array |
This class manages history for your mechanize object.
| max_size | [RW] |
# File lib/www/mechanize/history.rb, line 8
8: def initialize(max_size = nil)
9: @max_size = max_size
10: @history_index = {}
11: end
# File lib/www/mechanize/history.rb, line 38
38: def clear
39: @history_index.clear
40: super
41: end
# File lib/www/mechanize/history.rb, line 13
13: def initialize_copy(orig)
14: super
15: @history_index = orig.instance_variable_get(:@history_index).dup
16: end
# File lib/www/mechanize/history.rb, line 52
52: def pop
53: return nil if length == 0
54: page = super
55: remove_from_index(page)
56: page
57: end
# File lib/www/mechanize/history.rb, line 18
18: def push(page, uri = nil)
19: super(page)
20: @history_index[(uri ? uri : page.uri).to_s] = page
21: if @max_size && self.length > @max_size
22: while self.length > @max_size
23: self.shift
24: end
25: end
26: self
27: end
# File lib/www/mechanize/history.rb, line 43
43: def shift
44: return nil if length == 0
45: page = self[0]
46: self[0] = nil
47: super
48: remove_from_index(page)
49: page
50: end
# File lib/www/mechanize/history.rb, line 30
30: def visited?(url)
31: ! visited_page(url).nil?
32: end
# File lib/www/mechanize/history.rb, line 34
34: def visited_page(url)
35: @history_index[(url.respond_to?(:uri) ? url.uri : url).to_s]
36: end