Class: Racket::Utils::Routing::ActionCache
- Inherits:
-
Object
- Object
- Racket::Utils::Routing::ActionCache
- Defined in:
- lib/racket/utils/routing.rb
Overview
Class for caching actions
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#add(controller_class) ⇒ nil
Caches all actions for a controller class.
-
#initialize ⇒ ActionCache
constructor
A new instance of ActionCache.
-
#present?(controller_class, action) ⇒ true|false
Returns whether
controller_classis in the cache and that it contains the actionaction.
Constructor Details
#initialize ⇒ ActionCache
Returns a new instance of ActionCache.
30 31 32 |
# File 'lib/racket/utils/routing.rb', line 30 def initialize @items = {} end |
Instance Attribute Details
#items ⇒ Object (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.
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.
40 41 42 |
# File 'lib/racket/utils/routing.rb', line 40 def present?(controller_class, action) @items.fetch(controller_class, []).include?(action) end |