Sha256: 4267fef574585238e505212621ef9e2fdf886a5fd7fe6e08cc377589c8bfc0cf

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

class Roda
  module Endpoints
    # Generic HTTP endpoint abstraction.
    class Endpoint
      # Namespacing operations, validations, etc.
      module Namespace
        def self.included(child)
          child.attributes += %i(name ns parent)
        end

        # @param name [Symbol]
        # @param ns [String]
        # @param attributes [{Symbol=>Object}]
        # @param parent [Endpoint?]
        def initialize(name:, ns: name.to_s, parent: Undefined, **attributes)
          @name = name
          @ns = ns
          unless parent == Undefined
            @parent = parent
            @ns = "#{parent.ns}.#{ns}"
          end
          super(name: name, **attributes)
        end

        # @return [Symbol]
        attr_reader :name

        # @return [String]
        attr_reader :ns

        # @return [Endpoint]
        attr_reader :parent

        # @return [ROM::Repository]
        def repository
          container[@repository_key] if @repository_key
        end

        # @return [{Symbol=>Object}]
        def to_hash
          super.merge(repository: @repository_key)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roda-endpoints-0.1.0 lib/roda/endpoints/endpoint/namespace.rb