Class: Rspec::Autoswagger::DocParts
- Inherits:
-
Object
- Object
- Rspec::Autoswagger::DocParts
- Defined in:
- lib/rspec/autoswagger/doc_parts.rb
Constant Summary collapse
- DEFAULT_OUTPUT_PATH =
'./tmp'
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#specification ⇒ Object
readonly
Returns the value of attribute specification.
Instance Method Summary collapse
- #add(rspec_core_obj, example) ⇒ Object
- #aggregate ⇒ Object
-
#initialize ⇒ DocParts
constructor
A new instance of DocParts.
- #to_yaml ⇒ Object
Constructor Details
#initialize ⇒ DocParts
Returns a new instance of DocParts.
11 12 13 14 15 16 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 11 def initialize @info = Parts::Info.generate_hash @paths = {} @definitions = {} @specification = {} end |
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
6 7 8 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 6 def definitions @definitions end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
6 7 8 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 6 def info @info end |
#output_path ⇒ Object
Returns the value of attribute output_path.
7 8 9 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 7 def output_path @output_path end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
6 7 8 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 6 def paths @paths end |
#specification ⇒ Object (readonly)
Returns the value of attribute specification.
6 7 8 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 6 def specification @specification end |
Instance Method Details
#add(rspec_core_obj, example) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 22 def add(rspec_core_obj, example) doc_part = DocPart.new(rspec_core_obj, example) path, param_definitions = doc_part.create_path method = path.values.first.keys.first endpoint = path.keys.first if paths.keys.include?(endpoint) if paths[endpoint].keys.include?(method) paths.each do |key, value| value[method]['responses'].merge!(path.values.first[method]['responses']) if key.to_s == endpoint.to_s end else paths[endpoint].merge!(path.values.first) end else paths.merge!(path) end definitions.merge!(doc_part.create_definition(output_path)) definitions.merge!(param_definitions) unless param_definitions.empty? end |
#aggregate ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 42 def aggregate specification.merge!(info) specification.merge!({ 'paths' => paths }) specification.merge!({ 'definitions' => definitions }) specification end |
#to_yaml ⇒ Object
50 51 52 53 54 |
# File 'lib/rspec/autoswagger/doc_parts.rb', line 50 def to_yaml aggregate if specification.empty? FileUtils::mkdir_p(output_path) YAML.dump(specification, File.open(output_path + '/swagger.yml', 'w')) end |