Class: Merb::Router::CachedProc

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/dispatch/router/cached_proc.rb

Overview

Cache procs for future reference in eval statement

Constant Summary collapse

@@index =
0
@@list =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache) ⇒ CachedProc

Parameters

cache<Proc>

The block of code to cache.



13
14
15
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 13

def initialize(cache)
  @cache, @index = cache, CachedProc.register(self)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



9
10
11
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 9

def cache
  @cache
end

#indexObject

Returns the value of attribute index.



9
10
11
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 9

def index
  @index
end

Class Method Details

.[](index) ⇒ Object

Parameters

index<Fixnum>

The index of the cached code to retrieve.

Returns

CachedProc

The cached code at index.



48
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 48

def [](index) @@list[index] end

.[]=(index, code) ⇒ Object

Sets the cached code for a specific index.

Parameters

index<Fixnum>

The index of the cached code to set.

code<CachedProc>

The cached code to set.



41
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 41

def []=(index, code) @@list[index] = code end

.register(cached_code) ⇒ Object

Parameters

cached_code<CachedProc>

The cached code to register.

Returns

Fixnum

The index of the newly registered CachedProc.



30
31
32
33
34
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 30

def register(cached_code)
  CachedProc[@@index] = cached_code
  @@index += 1
  @@index - 1
end

Instance Method Details

#to_sObject

Returns

String

The CachedProc object in a format embeddable within a string.



19
20
21
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 19

def to_s
  "CachedProc[#{@index}].cache"
end