Class: Apicraft::Openapi::Contract

Inherits:
Object
  • Object
show all
Includes:
Concerns::Cacheable
Defined in:
lib/apicraft/openapi/contract.rb

Overview

A single openapi yaml file is represented by this Contract class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Cacheable

cache, #with_cache

Constructor Details

#initialize(document) ⇒ Contract

Returns a new instance of Contract.



13
14
15
# File 'lib/apicraft/openapi/contract.rb', line 13

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



11
12
13
# File 'lib/apicraft/openapi/contract.rb', line 11

def document
  @document
end

Class Method Details

.allObject



31
32
33
# File 'lib/apicraft/openapi/contract.rb', line 31

def all
  @store
end

.create!(document) ⇒ Object



25
26
27
28
29
# File 'lib/apicraft/openapi/contract.rb', line 25

def create!(document)
  c = new(document)
  @store << c
  c
end

.find_by_operation(method, path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/apicraft/openapi/contract.rb', line 35

def find_by_operation(method, path)
  found = nil

  all.each do |c|
    if c.operation(method, path).present?
      found = c
      break
    end
  end

  found
end

Instance Method Details

#operation(method, path) ⇒ Object



17
18
19
20
21
22
# File 'lib/apicraft/openapi/contract.rb', line 17

def operation(method, path)
  # with_cache("operation-#{method.downcase}-#{path}") do
  op = document.request_operation(method.downcase, path)
  Operation.new(op) if op.present?
  # end
end