Sha256: 07fcd859d313f0fc4ebee14fb6e160dbb2ff6232894452753b52a942f109f9b5

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

require 'roda/endpoints/endpoint/singleton'
require 'roda/endpoints/endpoint/data'
require 'forwardable'

class Roda
  module Endpoints
    class Endpoint
      # HTTP endpoint representing a specific item of collection uniquely
      # identified by some parameter.
      class Item < Singleton
        extend Forwardable

        prepend Data

        self.attributes += %i(id by on)
        self.defaults = defaults.merge(
          by: :fetch,
          on: :id,
          finder: -> { repository.public_send(by, id) }
        )

        # @return [Symbol]
        attr_reader :by

        # @return [Integer]
        def id
          @id ||= captures.first
        end

        # @return [Endpoint::Collection]
        def collection
          parent
        end

        def_delegator :collection, :repository
      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/item.rb