Module: Lennarb::Helpers

Defined in:
lib/lennarb/helpers.rb

Overview

Simple helpers module for Lennarb applications. Provides helper methods to be used in routes and hooks.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.app_helpersObject (readonly)

Get the app helpers map



10
11
12
# File 'lib/lennarb/helpers.rb', line 10

def app_helpers
  @app_helpers
end

Class Method Details

.define(app_class, mod_or_block = nil, &block) ⇒ Module

Define helpers for an app class

Parameters:

  • app_class (Class)

    The application class

  • mod_or_block (Module, Proc) (defaults to: nil)

    The module to include or block with helper definitions

Returns:

  • (Module)

    The helpers module



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lennarb/helpers.rb', line 25

def define(app_class, mod_or_block = nil, &block)
  mod = self.for(app_class)

  case mod_or_block
  when Module
    mod.include(mod_or_block)
  when Proc
    mod.module_eval(&mod_or_block)
  end

  mod.module_eval(&block) if block_given?
  mod
end

.for(app_class) ⇒ Module

Get helpers module for an app class

Parameters:

  • app_class (Class)

    The application class

Returns:

  • (Module)

    The helpers module



16
17
18
# File 'lib/lennarb/helpers.rb', line 16

def for(app_class)
  app_helpers[app_class] ||= Module.new
end