Class: Kanal::Core::Router::RouterStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/kanal/core/router/router_storage.rb

Overview

Class with helper methods for creating and getting routers

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ RouterStorage

Returns a new instance of RouterStorage.



10
11
12
13
# File 'lib/kanal/core/router/router_storage.rb', line 10

def initialize(core)
  @routers = []
  @core = core
end

Instance Method Details

#get_or_create_router(name) ⇒ Kanal::Core::Router::Router

Creates router by name and stores it for further access

Parameters:

  • name (Symbol)

    <description>

Returns:



22
23
24
25
26
27
28
29
30
31
# File 'lib/kanal/core/router/router_storage.rb', line 22

def get_or_create_router(name)
  router = @routers.find { |r| r.name == name }

  unless router
    router = Router.new name, @core
    @routers.append router
  end

  router
end