Class: Gumdrop::ContextPool

Inherits:
Object
  • Object
show all
Defined in:
lib/gumdrop/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(renderer, size = 3) ⇒ ContextPool

Returns a new instance of ContextPool.



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/gumdrop/renderer.rb', line 210

def initialize(renderer, size=3)
  @_current= -1
  @renderer= renderer
  @pool=[]
  prev= nil
  size.times do |i|
    ctx= RenderContext.new nil, nil, renderer, prev
    @pool << ctx
    prev= ctx
  end
end

Instance Method Details

#currentObject



234
235
236
# File 'lib/gumdrop/renderer.rb', line 234

def current
  @pool[@_current]
end

#nextObject



228
229
230
231
232
# File 'lib/gumdrop/renderer.rb', line 228

def next
  @_current += 1
  @pool << RenderContext.new( nil, nil, @renderer, prev ) if @_current == @pool.size
  @pool[@_current]      
end

#popObject



242
243
244
245
# File 'lib/gumdrop/renderer.rb', line 242

def pop
  @_current -= 1
  @pool[@_current]      
end

#prevObject



238
239
240
# File 'lib/gumdrop/renderer.rb', line 238

def prev
  @pool[@_current - 1] rescue nil
end

#rootObject



247
248
249
# File 'lib/gumdrop/renderer.rb', line 247

def root
  @pool[0]
end

#sizeObject



251
252
253
# File 'lib/gumdrop/renderer.rb', line 251

def size
  @_current + 1
end

#sub_contextObject



222
223
224
225
226
# File 'lib/gumdrop/renderer.rb', line 222

def sub_context
  result= yield self.next, self.prev
  self.pop
  result
end