Sha256: aeb2af6370491b24e8e239f01730295586592bb9f4fa5d28637bcf39bb638950

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

# frozen_string_literal: true

class Roda
  module Endpoints
    # Generic HTTP endpoint abstraction.
    class Endpoint
      # Accessing data inside of endpoint.
      module Data
        # @param name [String]
        # @param repository [String]
        # @param attributes [{Symbol=>Object}]
        def initialize(name:,
                       repository: "repositories.#{Inflecto.pluralize(name)}",
                       **attributes)
          @repository_key = repository
          super(name: name, **attributes)
        end

        # @return [String]
        attr_reader :repository_key

        # @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.3.0 lib/roda/endpoints/endpoint/data.rb