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 :api: private

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.

:api: private


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

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

Instance Attribute Details

#cacheObject

:api: private


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

def cache
  @cache
end

#indexObject

:api: private


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

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.

:api: private


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

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.

:api: private


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

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.

:api: private


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

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.

:api: private


25
26
27
# File 'lib/merb-core/dispatch/router/cached_proc.rb', line 25

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