Class: Racket::Utils::Helpers::HelperCache

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

Overview

Cache for helpers, ensuring that helpers get loaded exactly once.

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • _options (Hash) (defaults to: {})

    (unused)

Returns:

  • (Proc)


29
30
31
32
33
34
35
36
37
# File 'lib/racket/utils/helpers.rb', line 29

def self.service(_options = {})
  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.

Parameters:

  • helpers (Array)

    An array of symbols

Returns:

  • (Hash)


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