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.
Class Method Summary collapse
-
.service(_options = {}) ⇒ Proc
Returns a service proc that can be used by the registry.
Instance Method Summary collapse
-
#add(controller_class) ⇒ nil
Caches all actions for a controller class.
-
#initialize(logger) ⇒ ActionCache
constructor
A new instance of ActionCache.
-
#present?(controller_class, action) ⇒ true|false
Returns whether
controller_class
is in the cache and that it contains the actionaction
.
Constructor Details
#initialize(logger) ⇒ ActionCache
Returns a new instance of ActionCache.
38 39 40 41 |
# File 'lib/racket/utils/routing.rb', line 38 def initialize(logger) @items = {} @logger = logger end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
36 37 38 |
# File 'lib/racket/utils/routing.rb', line 36 def items @items end |
Class Method Details
.service(_options = {}) ⇒ Proc
Returns a service proc that can be used by the registry.
32 33 34 |
# File 'lib/racket/utils/routing.rb', line 32 def self.service( = {}) ->(reg) { new(reg.application_logger) } 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.
58 59 60 61 62 63 64 65 |
# File 'lib/racket/utils/routing.rb', line 58 def add(controller_class) __add(controller_class) actions = @items[controller_class].to_a @items[controller_class] = actions @logger.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
.
49 50 51 |
# File 'lib/racket/utils/routing.rb', line 49 def present?(controller_class, action) @items.fetch(controller_class, []).include?(action) end |