Class: GrapeSlate::Document
- Inherits:
-
GrapeMarkdown::Document
- Object
- GrapeMarkdown::Document
- GrapeSlate::Document
- Defined in:
- lib/grape-slate/document.rb
Instance Attribute Summary collapse
-
#api_class ⇒ Object
readonly
Returns the value of attribute api_class.
-
#document_template ⇒ Object
readonly
Returns the value of attribute document_template.
-
#properties_template ⇒ Object
readonly
Returns the value of attribute properties_template.
Instance Method Summary collapse
- #formatted_request_headers ⇒ Object
- #formatted_response_headers ⇒ Object
- #generate ⇒ Object
-
#initialize(api_class) ⇒ Document
constructor
A new instance of Document.
- #properties_table(resource) ⇒ Object
- #resources ⇒ Object
- #routes ⇒ Object
- #show_request_sample?(route) ⇒ Boolean
- #write ⇒ Object
Constructor Details
#initialize(api_class) ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 |
# File 'lib/grape-slate/document.rb', line 7 def initialize(api_class) @api_class = api_class @document_template = template_for(:document) @properties_template = template_for(:properties) end |
Instance Attribute Details
#api_class ⇒ Object (readonly)
Returns the value of attribute api_class.
3 4 5 |
# File 'lib/grape-slate/document.rb', line 3 def api_class @api_class end |
#document_template ⇒ Object (readonly)
Returns the value of attribute document_template.
3 4 5 |
# File 'lib/grape-slate/document.rb', line 3 def document_template @document_template end |
#properties_template ⇒ Object (readonly)
Returns the value of attribute properties_template.
3 4 5 |
# File 'lib/grape-slate/document.rb', line 3 def properties_template @properties_template end |
Instance Method Details
#formatted_request_headers ⇒ Object
43 44 45 |
# File 'lib/grape-slate/document.rb', line 43 def formatted_request_headers formatted_headers(GrapeSlate::Config.request_headers) end |
#formatted_response_headers ⇒ Object
47 48 49 |
# File 'lib/grape-slate/document.rb', line 47 def formatted_response_headers formatted_headers(GrapeSlate::Config.response_headers) end |
#generate ⇒ Object
13 14 15 |
# File 'lib/grape-slate/document.rb', line 13 def generate ERB.new(document_template, nil, '-').result(binding) end |
#properties_table(resource) ⇒ Object
39 40 41 |
# File 'lib/grape-slate/document.rb', line 39 def properties_table(resource) ERB.new(properties_template, nil, '-').result(resource.resource_binding) end |
#resources ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grape-slate/document.rb', line 27 def resources @resources ||= begin grouped_routes = routes.group_by(&:route_name).reject do |name, routes| resource_exclusion.include?(name.to_sym) end grouped_routes.map do |name, routes| GrapeMarkdown::Resource.new(name, routes) end end end |
#routes ⇒ Object
21 22 23 24 25 |
# File 'lib/grape-slate/document.rb', line 21 def routes @routes ||= api_class.routes.map do |route| GrapeMarkdown::Route.new(route) end end |
#show_request_sample?(route) ⇒ Boolean
51 52 53 |
# File 'lib/grape-slate/document.rb', line 51 def show_request_sample?(route) %w(PUT POST).include?(route.route_method) end |
#write ⇒ Object
17 18 19 |
# File 'lib/grape-slate/document.rb', line 17 def write fail 'Not yet supported' end |