Class: RspecContracts::Contract
- Inherits:
-
Object
- Object
- RspecContracts::Contract
show all
- Defined in:
- lib/rspec_contracts/contract.rb
Instance Method Summary
collapse
Constructor Details
#initialize(schema) ⇒ Contract
Returns a new instance of Contract.
5
6
7
8
|
# File 'lib/rspec_contracts/contract.rb', line 5
def initialize(schema)
@schema = schema.with_indifferent_access
@root = OpenAPIParser.parse(schema)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
36
37
38
|
# File 'lib/rspec_contracts/contract.rb', line 36
def method_missing(m, *args, &block)
@root.send(m, *args, &block)
end
|
Instance Method Details
#[](key) ⇒ Object
10
11
12
13
14
|
# File 'lib/rspec_contracts/contract.rb', line 10
def [](key)
return RspecContracts::Operation.new(nil, self) unless operations.key?(key)
operations[key]
end
|
#operations ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/rspec_contracts/contract.rb', line 22
def operations
@operations ||= paths.map do |p|
p._openapi_all_child_objects.values.map do |op|
next unless op.respond_to?(:operation_id)
[op.operation_id, RspecContracts::Operation.new(op, self)]
end.compact.to_h
end.inject(:merge).with_indifferent_access
end
|
#paths ⇒ Object
32
33
34
|
# File 'lib/rspec_contracts/contract.rb', line 32
def paths
@paths ||= @root.paths._openapi_all_child_objects.values
end
|
#version ⇒ Object
16
17
18
19
20
|
# File 'lib/rspec_contracts/contract.rb', line 16
def version
@schema[:info][:version]
rescue NoMethodError => _e
raise RspecContracts::Error.new("Version not found in schema")
end
|