Class: Racket::Utils::Helpers::HelperCache
- Inherits:
-
Object
- Object
- Racket::Utils::Helpers::HelperCache
- Defined in:
- lib/racket/utils/helpers.rb
Overview
Cache for helpers, ensuring that helpers get loaded exactly once.
Class Method Summary collapse
-
.service(_options = {}) ⇒ Proc
Returns a service proc that can be used by the registry.
Instance Method Summary collapse
-
#initialize(helper_dir, logger, utils) ⇒ HelperCache
constructor
A new instance of HelperCache.
-
#load_helpers(helpers) ⇒ Hash
Loads helper files and return the loadad modules as a hash.
Constructor Details
#initialize(helper_dir, logger, utils) ⇒ HelperCache
Returns a new instance of HelperCache.
39 40 41 42 43 44 |
# File 'lib/racket/utils/helpers.rb', line 39 def initialize(helper_dir, logger, utils) @helper_dir = helper_dir @helpers = {} @logger = logger @utils = utils end |
Class Method Details
.service(_options = {}) ⇒ Proc
Returns a service proc that can be used by the registry.
29 30 31 32 33 34 35 36 37 |
# File 'lib/racket/utils/helpers.rb', line 29 def self.service( = {}) lambda do |reg| new( reg.application_settings.helper_dir, reg.application_logger, reg.utils ) end end |
Instance Method Details
#load_helpers(helpers) ⇒ Hash
Loads helper files and return the loadad modules as a hash. Any helper files that cannot be loaded are excluded from the result.
51 52 53 54 55 56 57 58 |
# File 'lib/racket/utils/helpers.rb', line 51 def load_helpers(helpers) helper_modules = {} helpers.each do |helper| helper_module = load_helper(helper) helper_modules[helper] = helper_module if helper_module end helper_modules end |