Class: RspecApiDocumentation::Writers::JsonExample
- Inherits:
-
Object
- Object
- RspecApiDocumentation::Writers::JsonExample
show all
- Defined in:
- lib/rspec_api_documentation/writers/json_writer.rb,
lib/rspec_api_documentation/writers/json_iodocs_writer.rb
Instance Method Summary
collapse
Constructor Details
#initialize(example, configuration) ⇒ JsonExample
Returns a new instance of JsonExample.
64
65
66
67
68
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 64
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
70
71
72
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 70
def method_missing(method, *args, &block)
@example.send(method, *args, &block)
end
|
Instance Method Details
#as_json(opts = nil) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 87
def as_json(opts = nil)
{
:resource => resource_name,
: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
78
79
80
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 78
def dirname
resource_name.to_s.downcase.gsub(/\s+/, '_').sub(/^\//,'')
end
|
#filename ⇒ Object
82
83
84
85
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 82
def filename
basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
"#{basename}.json"
end
|
#parameters ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rspec_api_documentation/writers/json_iodocs_writer.rb', line 60
def parameters
params = []
if @example.respond_to?(:parameters)
@example.parameters.map do |param|
params << {
"Name" => param[:name],
"Description" => param[:description],
"Default" => "",
"Required" => param[:required] ? "Y" : "N"
}
end
end
params
end
|
#requests ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 100
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
74
75
76
|
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 74
def respond_to?(method, include_private = false)
super || @example.respond_to?(method, include_private)
end
|