Class: OasRails::Spec::PathItem

Inherits:
Object
  • Object
show all
Includes:
Specable
Defined in:
lib/oas_rails/spec/path_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Specable

#as_json, #to_spec

Constructor Details

#initialize(specification) ⇒ PathItem

Returns a new instance of PathItem.



7
8
9
10
11
12
13
14
# File 'lib/oas_rails/spec/path_item.rb', line 7

def initialize(specification)
  @specification = specification
  @get = nil
  @post = nil
  @put = nil
  @patch = nil
  @delete = nil
end

Instance Attribute Details

#deleteObject (readonly)

Returns the value of attribute delete.



5
6
7
# File 'lib/oas_rails/spec/path_item.rb', line 5

def delete
  @delete
end

#getObject (readonly)

Returns the value of attribute get.



5
6
7
# File 'lib/oas_rails/spec/path_item.rb', line 5

def get
  @get
end

#patchObject (readonly)

Returns the value of attribute patch.



5
6
7
# File 'lib/oas_rails/spec/path_item.rb', line 5

def patch
  @patch
end

#postObject (readonly)

Returns the value of attribute post.



5
6
7
# File 'lib/oas_rails/spec/path_item.rb', line 5

def post
  @post
end

#putObject (readonly)

Returns the value of attribute put.



5
6
7
# File 'lib/oas_rails/spec/path_item.rb', line 5

def put
  @put
end

Instance Method Details

#add_operation(http_method, operation) ⇒ Object



24
25
26
# File 'lib/oas_rails/spec/path_item.rb', line 24

def add_operation(http_method, operation)
  instance_variable_set("@#{http_method}", operation)
end

#fill_from(path, route_extractor: Extractors::RouteExtractor) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/oas_rails/spec/path_item.rb', line 16

def fill_from(path, route_extractor: Extractors::RouteExtractor)
  route_extractor.host_routes_by_path(path).each do |oas_route|
    add_operation(oas_route.verb.downcase, Spec::Operation.new(@specification).fill_from(oas_route))
  end

  self
end

#oas_fieldsObject



28
29
30
# File 'lib/oas_rails/spec/path_item.rb', line 28

def oas_fields
  [:get, :post, :put, :patch, :delete]
end