Sha256: db084b15a9a978a25647615c870ce5b87094d28e1ef1f5fb5c2c2d0330a1e593

Contents?: true

Size: 771 Bytes

Versions: 9

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

require_relative "./router"

module Kanal
  module Core
    module Router
      # Class with helper methods for creating and getting routers
      class RouterStorage
        def initialize(core)
          @routers = []
          @core = core
        end

        #
        # Creates router by name and stores it for further access
        #
        # @param [Symbol] name <description>
        #
        # @return [Kanal::Core::Router::Router] <description>
        #
        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
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kanal-0.8.0 lib/kanal/core/router/router_storage.rb
kanal-0.7.0 lib/kanal/core/router/router_storage.rb
kanal-0.6.0 lib/kanal/core/router/router_storage.rb
kanal-0.5.1 lib/kanal/core/router/router_storage.rb
kanal-0.5.0 lib/kanal/core/router/router_storage.rb
kanal-0.4.3 lib/kanal/core/router/router_storage.rb
kanal-0.4.2 lib/kanal/core/router/router_storage.rb
kanal-0.4.1 lib/kanal/core/router/router_storage.rb
kanal-0.4.0 lib/kanal/core/router/router_storage.rb