Class: SanaRouter::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/sana_router.rb

Overview

router events

Instance Method Summary collapse

Constructor Details

#initialize(route, mapping, load_controller, unload_controller, default_controller = nil) ⇒ Events

constructor

Parameters:

  • route (Hash<Symbol, SanaController>)

    route hash

  • mapping (Hash<Symbol, Hash<Symbol, Integer>>)

    mapping hash

  • load_controller (SanaController)

    load controller

  • unload_controller (SanaController)

    unload controller

  • default_controller (SanaController) (defaults to: nil)

    default controller


93
94
95
96
97
98
99
# File 'lib/sana_router.rb', line 93

def initialize(route, mapping, load_controller, unload_controller, default_controller = nil)
  @route = route
  @mapping = mapping
  @load_controller = load_controller
  @unload_controller = unload_controller
  @default_controller = default_controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, request) ⇒ String, Openstruct

SHIORI request()

Examples:

request()

events.OnBoot(request)

Parameters:

  • method (Symbol)

    method name = event id

  • request (OpenStruct)

    request

Returns:

  • (String, Openstruct)

    response


107
108
109
110
111
112
113
# File 'lib/sana_router.rb', line 107

def method_missing(method, request)
  if controller = @route[method] || @default_controller
    controller.new(self, method, request, @mapping[method]).action
  else
    super
  end
end

Instance Method Details

#_load(dirpath) ⇒ Object

SHIORI load()

Parameters:

  • dirpath (String)

    “ghost/master” path


117
118
119
# File 'lib/sana_router.rb', line 117

def _load(dirpath)
  @load_controller.new(self, __method__, nil, nil)._load(dirpath)
end

#_unloadObject

SHIORI unload()


122
123
124
# File 'lib/sana_router.rb', line 122

def _unload
  @load_controller.new(self, __method__, nil, nil)._unload
end