Class: RspecApiDocumentation::Writers::JSONExample
- Inherits:
-
Object
- Object
- RspecApiDocumentation::Writers::JSONExample
show all
- Defined in:
- lib/rspec_api_documentation/writers/json_writer.rb
Instance Method Summary
collapse
Constructor Details
#initialize(example, configuration) ⇒ JSONExample
Returns a new instance of JSONExample.
69
70
71
72
73
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 69
def initialize(example, configuration)
@example = example
@host = configuration.curl_host
@filter_headers = configuration.
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
75
76
77
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 75
def method_missing(method, *args, &block)
@example.send(method, *args, &block)
end
|
Instance Method Details
#as_json(opts = nil) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 92
def as_json(opts = nil)
{
:resource => resource_name,
:resource_explanation => resource_explanation,
:http_method => http_method,
:route => route,
:description => description,
:explanation => explanation,
:parameters => respond_to?(:parameters) ? parameters : [],
:response_fields => respond_to?(:response_fields) ? response_fields : [],
:requests => requests
}
end
|
#dirname ⇒ Object
83
84
85
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 83
def dirname
resource_name.to_s.downcase.gsub(/\s+/, '_').sub(/^\//,'')
end
|
#filename ⇒ Object
87
88
89
90
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 87
def filename
basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
"#{basename}.json"
end
|
#requests ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 106
def requests
super.map do |hash|
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
79
80
81
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 79
def respond_to?(method, include_private = false)
super || @example.respond_to?(method, include_private)
end
|