Class: GrapeSlate::Document

Inherits:
GrapeMarkdown::Document
  • Object
show all
Defined in:
lib/grape-slate/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject (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_templateObject (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_templateObject (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_headersObject



43
44
45
# File 'lib/grape-slate/document.rb', line 43

def formatted_request_headers
  formatted_headers(GrapeSlate::Config.request_headers)
end

#formatted_response_headersObject



47
48
49
# File 'lib/grape-slate/document.rb', line 47

def formatted_response_headers
  formatted_headers(GrapeSlate::Config.response_headers)
end

#generateObject



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

#resourcesObject



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

#routesObject



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

Returns:

  • (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

#writeObject



17
18
19
# File 'lib/grape-slate/document.rb', line 17

def write
  fail 'Not yet supported'
end