class Mechanize::History
This class manages history for your mechanize object.
Attributes
Public Class Methods
Source
# File lib/mechanize/history.rb, line 9 def initialize(max_size = nil) @max_size = max_size @history_index = {} end
Public Instance Methods
Source
# File lib/mechanize/history.rb, line 51 def clear @history_index.clear super end
Calls superclass method
Source
# File lib/mechanize/history.rb, line 14 def initialize_copy(orig) super @history_index = orig.instance_variable_get(:@history_index).dup end
Calls superclass method
Source
# File lib/mechanize/history.rb, line 67 def pop return nil if length == 0 page = super remove_from_index(page) page end
Calls superclass method
Source
# File lib/mechanize/history.rb, line 25 def push(page, uri = nil) super page index = uri ? uri : page.uri @history_index[index.to_s] = page shift while length > @max_size if @max_size self end
Calls superclass method
Also aliased as: <<
Source
# File lib/mechanize/history.rb, line 56 def shift return nil if length == 0 page = self[0] self[0] = nil super remove_from_index(page) page end
Calls superclass method
Source
# File lib/mechanize/history.rb, line 38 def visited? uri page = @history_index[uri.to_s] return page if page # HACK uri = uri.dup uri.path = '/' if uri.path.empty? @history_index[uri.to_s] end
Also aliased as: visited_page
Private Instance Methods
Source
# File lib/mechanize/history.rb, line 76 def remove_from_index(page) @history_index.each do |k,v| @history_index.delete(k) if v == page end end