history without inheriting Array
parent
f0889b8b64
commit
9d797600f9
|
@ -1,17 +1,20 @@
|
|||
require "./page"
|
||||
|
||||
class MechanizeCr::History < Array(MechanizeCr::Page)
|
||||
class MechanizeCr::History
|
||||
property max_size : Int32
|
||||
property array : Array(MechanizeCr::Page)
|
||||
|
||||
forward_missing_to @array
|
||||
|
||||
def initialize(max_size = 100)
|
||||
@max_size = max_size
|
||||
super
|
||||
@array = Array(MechanizeCr::Page).new
|
||||
end
|
||||
|
||||
def push(page, uri = nil)
|
||||
super page
|
||||
while self.size > @max_size
|
||||
shift
|
||||
@array.push(page)
|
||||
while size > @max_size
|
||||
@array.shift
|
||||
end
|
||||
self
|
||||
end
|
||||
|
@ -20,6 +23,6 @@ class MechanizeCr::History < Array(MechanizeCr::Page)
|
|||
if size == 0
|
||||
# TODO: raise error
|
||||
end
|
||||
page = super
|
||||
page = @array.pop
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue