Class: RspecApiDocumentation::Views::MarkupExample

Inherits:
Mustache
  • Object
show all
Defined in:
lib/rspec_api_documentation/views/markup_example.rb

Constant Summary collapse

SPECIAL_CHARS =
/[<>:"\/\\|?*]/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(example, configuration) ⇒ MarkupExample

Returns a new instance of MarkupExample.



8
9
10
11
12
13
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



15
16
17
# File 'lib/rspec_api_documentation/views/markup_example.rb', line 15

def method_missing(method, *args, &block)
  @example.send(method, *args, &block)
end

Instance Method Details

#dirnameObject



23
24
25
# File 'lib/rspec_api_documentation/views/markup_example.rb', line 23

def dirname
  sanitize(resource_name.to_s.downcase)
end

#extensionObject



65
66
67
# File 'lib/rspec_api_documentation/views/markup_example.rb', line 65

def extension
  raise 'Parent class. This method should not be called.'
end

#filenameObject



27
28
29
30
31
# 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

#parametersObject



33
34
35
36
37
38
39
# 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

#requestsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# 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_fieldsObject



41
42
43
44
45
46
47
# 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