Module: DaylightDocumentation::DocumentationHelper

Defined in:
app/helpers/daylight_documentation/documentation_helper.rb

Overview

Helper methods for rendering the endpoint/model documentation.

Constant Summary collapse

ACTION_DEFINITIONS =
{
  'index'      => "Retrieves a list of %{names}",
  'create'     => "Creates a new %{name}",
  'show'       => "Retrieves a %{name} by an ID",
  'update'     => "Updates a %{name}",
  'associated' => "Returns %{name}\'s %{associated}",
  'remoted'    => "Calls %{name}\'s remote method %{remoted}"
}

Instance Method Summary collapse

Instance Method Details

#action_definition(defaults, model) ⇒ Object

A description of a route given the route defaults and model class.



34
35
36
37
38
39
40
41
# File 'app/helpers/daylight_documentation/documentation_helper.rb', line 34

def action_definition(defaults, model)
  ACTION_DEFINITIONS[defaults[:action]] % {
    name:       model.name.titleize.downcase,
    names:      model.name.titleize.pluralize.downcase,
    associated: defaults[:associated].to_s.pluralize.tr('_', ' '),
    remoted:    defaults[:remoted]
  }
end

#api_versionObject



47
48
49
# File 'app/helpers/daylight_documentation/documentation_helper.rb', line 47

def api_version
  Daylight::API.version.downcase
end

#client_namespaceObject



43
44
45
# File 'app/helpers/daylight_documentation/documentation_helper.rb', line 43

def client_namespace
  Daylight::API.namespace
end

#model_filters(model) ⇒ Object

A list of all the possible filters for the given model.



28
29
30
# File 'app/helpers/daylight_documentation/documentation_helper.rb', line 28

def model_filters(model)
  model.attribute_names + model.reflection_names
end

#model_verbs_and_routes(model) ⇒ Object

Yield all of the route information for the given model.

Yields route verb (GET, POST, etc), path specification, route defaults



18
19
20
21
22
23
24
# File 'app/helpers/daylight_documentation/documentation_helper.rb', line 18

def model_verbs_and_routes(model)
  routes = Daylight::Documentation.routes.routes.select {|route| route.path.spec.to_s.include? "/#{model.name.underscore.pluralize}" }

  routes.each do |route|
    yield route_verb(route), route.path.spec, route.defaults
  end
end