Sha256: 97d0b8334bc1cc02022e9ce47a4768f00b8f369878d421861fd0c718616eddd5

Contents?: true

Size: 1017 Bytes

Versions: 4

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

module Hanami
  module Middleware
    # Trie node to register scopes with custom Rack middleware
    #
    # @api private
    # @since 2.0.0
    class Node
      # @api private
      # @since 2.0.0
      attr_reader :app

      # @api private
      # @since 2.0.0
      def initialize
        @app = nil
        @children = {}
      end

      # @api private
      # @since 2.0.0
      def freeze
        @children.freeze
        super
      end

      # @api private
      # @since 2.0.0
      def put(segment)
        @children[segment] ||= self.class.new
      end

      # @api private
      # @since 2.0.0
      def get(segment)
        @children.fetch(segment) { self if leaf? }
      end

      # @api private
      # @since 2.0.0
      def app!(app)
        @app = app
      end

      # @api private
      # @since 2.0.0
      def app?
        !@app.nil?
      end

      # @api private
      # @since 2.0.0
      def leaf?
        @children.empty?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hanami-router-2.0.2 lib/hanami/middleware/node.rb
hanami-router-2.0.1 lib/hanami/middleware/node.rb
hanami-router-2.0.0 lib/hanami/middleware/node.rb
hanami-router-2.0.0.rc1 lib/hanami/middleware/node.rb