Class: Rspec::Autoswagger::DocPart
- Inherits:
-
Object
- Object
- Rspec::Autoswagger::DocPart
- Defined in:
- lib/rspec/autoswagger/doc_part.rb
Instance Attribute Summary collapse
-
#example ⇒ Object
readonly
Returns the value of attribute example.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#rspec_core_obj ⇒ Object
readonly
Returns the value of attribute rspec_core_obj.
Instance Method Summary collapse
- #create_definition(output_path = nil) ⇒ Object
- #create_path ⇒ Object
- #get_converted_path(path) ⇒ Object
-
#initialize(rspec_core_obj, example) ⇒ DocPart
constructor
A new instance of DocPart.
- #response_name ⇒ Object
Constructor Details
#initialize(rspec_core_obj, example) ⇒ DocPart
Returns a new instance of DocPart.
12 13 14 15 16 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 12 def initialize(rspec_core_obj, example) @rspec_core_obj = rspec_core_obj @request = rspec_core_obj.request @example = example end |
Instance Attribute Details
#example ⇒ Object (readonly)
Returns the value of attribute example.
10 11 12 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 10 def example @example end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
10 11 12 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 10 def request @request end |
#rspec_core_obj ⇒ Object (readonly)
Returns the value of attribute rspec_core_obj.
10 11 12 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 10 def rspec_core_obj @rspec_core_obj end |
Instance Method Details
#create_definition(output_path = nil) ⇒ Object
62 63 64 65 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 62 def create_definition(output_path = nil) definition = Parts::Definition.new(rspec_core_obj.response.body, response_name, output_path) definition.generate_definitions end |
#create_path ⇒ Object
57 58 59 60 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 57 def create_path path = Parts::Path.new(rspec_core_obj, example, response_name) path.generate_hash end |
#get_converted_path(path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 45 def get_converted_path(path) path.split("/").map do |path_element| if Util.detect_uuid(path_element) ":id" elsif Util.detect_uuid(path_element) ":id" else path_element end end.join("/") end |
#response_name ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rspec/autoswagger/doc_part.rb', line 18 def response_name status = rspec_core_obj.response.status.to_s if status == '200' path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2] if path.blank? path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '') path = get_converted_path(path) end if request.method == "GET" path.gsub(/\/|:/, '').camelize else path.gsub(/\/|:/, '').camelize + request.method.downcase.camelize end else path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2] if path.blank? path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '') path = get_converted_path(path) end if request.method == "GET" path.gsub(/\/|:/, '').camelize + status else path.gsub(/\/|:/, '').camelize + status + request.method.downcase.camelize end end end |