# frozen_string_literal: true require 'forwardable' class Roda module Endpoints # Generic HTTP endpoint abstraction. class Endpoint # Accessing data inside of endpoint. module Verbs extend Forwardable # @param [] only # @param [] except # @param attributes [{Symbol=>Object}] def initialize(only: implemented_verbs, except: [], **attributes) only = Array(only).flatten except = Array(except).flatten if ((unknown_only = only - implemented_verbs) + (unknown_except = except - implemented_verbs)).any? params = { only: unknown_only, except: unknown_except } raise ArgumentError, "unknown verbs in params: #{params}" end @verbs = only - except super(**attributes) end # @return [] def implemented_verbs self.class.verbs.to_a end # @return [] attr_reader :verbs def verb(name, **kwargs, &block) key = "operations.#{ns}.#{name}" container.register key, &block singleton_class.verb(name, **kwargs, &container[key]) end def_delegator :singleton_class, :verb end end end end