Sha256: 947203bc5dd466593d2101b64eaae63e5ced2eea63d5d754baa1c614d4154192

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

module Kanpachi
  # Module to keep track of all APIs
  #
  # @api public
  module APIList
    module_function

    @list ||= {}

    # Returns a hash of APIs
    #
    # @return [Hash<Kanpachi::API>] All the added APIs.
    # @api public
    def to_hash
      @list
    end

    # Returns an array of APIs
    #
    # @return [Array<Kanpachi::API>] List of added APIs.
    # @api public
    def all
      @list.values
    end

    # Add a resource to the list
    #
    # @param [Kanpachi::API] The API to add.
    # @return [Hash<Kanpachi::API>] All the added APIs.
    # @raise DuplicateAPI If a resource is being duplicated.
    # @api public
    def add(api)
      @list[api.name] = api
    end

    # Delete a resource to the list
    #
    # @param [String] The name of the API to delete.
    # @api public
    def delete(name)
      @list.delete(name)
    end

    # Returns a API based on its name
    #
    # @param [String] name The name of the API you are looking for.
    # @return [Kanpachi::API] The found API.
    #
    # @api public
    def find(name)
      @list[name]
    end

    # Clears all APIs
    #
    # @api public
    def clear
      @list = {}
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kanpachi-0.0.7 lib/kanpachi/api_list.rb
kanpachi-0.0.6 lib/kanpachi/api_list.rb
kanpachi-0.0.5 lib/kanpachi/api_list.rb
kanpachi-0.0.4 lib/kanpachi/api_list.rb
kanpachi-0.0.3 lib/kanpachi/api_list.rb
kanpachi-0.0.2 lib/kanpachi/api_list.rb
kanpachi-0.0.1 lib/kanpachi/api_list.rb