Sha256: a8c2e461c137c800fa2853d97fed6d3af91d46e1ee9bcac66b3b99569e71940d

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'rspec_api_docs/formatter/resource/example'
require 'rspec_api_docs/formatter/resource/parameter'
require 'rspec_api_docs/formatter/resource/response_field'

module RspecApiDocs
  class Resource
    attr_reader :rspec_example

    def initialize(rspec_example)
      @rspec_example = rspec_example
      @examples = []
    end

    # The name of the resource.
    #
    # E.g. "Characters"
    #
    # @return [String]
    def name
      metadata.fetch(:resource_name, rspec_example.metadata[:example_group][:description])
    end

    # The description of the resource.
    #
    # E.g. "Orders can be created, viewed, and deleted"
    #
    # @return [String]
    def description
      metadata[:resource_description]
    end

    # Returns an array of {Example}s
    #
    # @return [Array<Example>]
    def examples
      @examples.sort_by(&:name)
    end

    # Add an example
    #
    # @return [void]
    def add_example(example)
      @examples << example
    end

    private

    def metadata
      rspec_example.metadata[METADATA_NAMESPACE]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-api-docs-0.8.0 lib/rspec_api_docs/formatter/resource.rb