Class: Racket::Utils::Routing::ActionCache

Inherits:
Object
  • Object
show all
Defined in:
lib/racket/utils/routing.rb

Overview

Class for caching actions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActionCache

Returns a new instance of ActionCache.



30
31
32
# File 'lib/racket/utils/routing.rb', line 30

def initialize
  @items = {}
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



28
29
30
# File 'lib/racket/utils/routing.rb', line 28

def items
  @items
end

Instance Method Details

#add(controller_class) ⇒ nil

Caches all actions for a controller class. This is used on every request to quickly decide whether an action is valid or not.

Parameters:

  • controller_class (Class)

Returns:

  • (nil)


49
50
51
52
53
54
55
56
# File 'lib/racket/utils/routing.rb', line 49

def add(controller_class)
  __add(controller_class)
  actions = @items[controller_class].to_a
  @items[controller_class] = actions
  ::Racket::Application.inform_dev(
    "Registering actions #{actions} for #{controller_class}."
  ) && nil
end

#present?(controller_class, action) ⇒ true|false

Returns whether controller_class is in the cache and that it contains the action action.

Parameters:

  • controller_class (Class)
  • action (Symbol)

Returns:

  • (true|false)


40
41
42
# File 'lib/racket/utils/routing.rb', line 40

def present?(controller_class, action)
  @items.fetch(controller_class, []).include?(action)
end