Sha256: cbfabfcb3200042c98392a3f51385ae650dc7901d5a3cb73964fbb2534d25e0e

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'swagger/swagger_object'
require 'swagger/v2/operation'

module Swagger
  module V2
    # Class representing a Swagger "Path Item Object".
    # @see https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#pathItemObject Path Item Object
    class Path < SwaggerObject
      extend Forwardable
      def_delegator :parent, :host

      VERBS = [:get, :put, :post, :delete, :options, :head, :patch]
      VERBS.each do | verb |
        field verb, Operation
      end
      field :parameters, Array[Parameter]

      def initialize(hash)
        hash[:parameters] ||= []
        super
      end

      def operations
        VERBS.each_with_object({}) do | v, h |
          operation = send v
          h[v] = operation if operation
        end
      end

      def uri_template
        "#{parent.host}#{parent.base_path}#{path}"
      end

      def path
        parent.paths.key self
      end

      # Iterates over each Path level parameter.
      def each_parameter
        return if parameters.nil?
        parameters.each do | parameter |
          yield parameter
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
swagger-core-0.2.3 lib/swagger/v2/path.rb
swagger-core-0.2.2 lib/swagger/v2/path.rb