class RspecApiDocumentation::Views::MarkupExample

Constants

SPECIAL_CHARS

Public Class Methods

new(example, configuration) click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 8
def initialize(example, configuration)
  @example = example
  @host = configuration.curl_host
  @filter_headers = configuration.curl_headers_to_filter
  self.template_path = configuration.template_path
end

Public Instance Methods

dirname() click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 23
def dirname
  sanitize(resource_name.to_s.downcase)
end
extension() click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 65
def extension
  raise 'Parent class. This method should not be called.'
end
filename() click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 27
def filename
  basename = sanitize(description.downcase)
  basename = Digest::MD5.new.update(description).to_s if basename.blank?
  "#{basename}.#{extension}"
end
method_missing(method, *args, &block) click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 15
def method_missing(method, *args, &block)
  @example.send(method, *args, &block)
end
parameters() click to toggle source
Calls superclass method
# File lib/rspec_api_documentation/views/markup_example.rb, line 33
def parameters
  super.each do |parameter|
    if parameter.has_key?(:scope)
      parameter[:scope] = format_scope(parameter[:scope])
    end
  end
end
requests() click to toggle source
Calls superclass method
# File lib/rspec_api_documentation/views/markup_example.rb, line 49
def requests
  super.map do |hash|
    hash[:request_headers_text] = format_hash(hash[:request_headers])
    hash[:request_query_parameters_text] = format_hash(hash[:request_query_parameters])
    hash[:response_headers_text] = format_hash(hash[:response_headers])
    if @host
      if hash[:curl].is_a? RspecApiDocumentation::Curl
        hash[:curl] = hash[:curl].output(@host, @filter_headers)
      end
    else
      hash[:curl] = nil
    end
    hash
  end
end
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/rspec_api_documentation/views/markup_example.rb, line 19
def respond_to?(method, include_private = false)
  super || @example.respond_to?(method, include_private)
end
response_fields() click to toggle source
Calls superclass method
# File lib/rspec_api_documentation/views/markup_example.rb, line 41
def response_fields
  super.each do |response_field|
    if response_field.has_key?(:scope)
      response_field[:scope] = format_scope(response_field[:scope])
    end
  end
end

Private Instance Methods

content_type(headers) click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 88
def content_type(headers)
  headers && headers.fetch("Content-Type", nil)
end
format_hash(hash = {}) click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 71
def format_hash(hash = {})
  return nil unless hash.present?
  hash.collect do |k, v|
    "#{k}: #{v}"
  end.join("\n")
end
format_scope(unformatted_scope) click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 78
def format_scope(unformatted_scope)
  Array(unformatted_scope).each_with_index.map do |scope, index|
    if index == 0
      scope
    else
      "[#{scope}]"
    end
  end.join
end
sanitize(name) click to toggle source
# File lib/rspec_api_documentation/views/markup_example.rb, line 92
def sanitize(name)
  name.gsub(/\s+/, '_').gsub(SPECIAL_CHARS, '')
end