Class: RailsContractSync::OpenAPIDocument
- Inherits:
-
Object
- Object
- RailsContractSync::OpenAPIDocument
- Defined in:
- lib/rails_contract_sync/openapi_document.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ OpenAPIDocument
constructor
A new instance of OpenAPIDocument.
- #operation(path, verb) ⇒ Object
- #paths ⇒ Object
- #set_operation(path, verb, op_hash) ⇒ Object
- #to_h ⇒ Object
- #to_yaml ⇒ Object
- #write(path) ⇒ Object
Constructor Details
#initialize(hash = nil) ⇒ OpenAPIDocument
Returns a new instance of OpenAPIDocument.
11 12 13 14 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 11 def initialize(hash = nil) @doc = deep_dup(hash) || skeleton @doc["paths"] ||= {} end |
Class Method Details
.load_file(path) ⇒ Object
5 6 7 8 9 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 5 def self.load_file(path) return new unless File.exist?(path) new(YAML.safe_load_file(path)) end |
Instance Method Details
#operation(path, verb) ⇒ Object
20 21 22 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 20 def operation(path, verb) paths.dig(path, verb.to_s.downcase) end |
#paths ⇒ Object
16 17 18 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 16 def paths @doc["paths"] end |
#set_operation(path, verb, op_hash) ⇒ Object
24 25 26 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 24 def set_operation(path, verb, op_hash) (paths[path] ||= {})[verb.to_s.downcase] = op_hash end |
#to_h ⇒ Object
28 29 30 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 28 def to_h deep_sort(deep_dup(@doc)) end |
#to_yaml ⇒ Object
32 33 34 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 32 def to_yaml to_h.to_yaml end |
#write(path) ⇒ Object
36 37 38 |
# File 'lib/rails_contract_sync/openapi_document.rb', line 36 def write(path) File.write(path, to_yaml) end |