Class: WeaselDiesel::Documentation

Inherits:
Object
  • Object
show all
Defined in:
lib/documentation.rb

Overview

Service documentation class

Defined Under Namespace

Classes: ElementDoc, NamespacedParam

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocumentation

Initialize a Documentation object wrapping all the documentation aspect of the service. The response documentation is a Documentation instance living inside the service documentation object.



81
82
83
84
85
86
# File 'lib/documentation.rb', line 81

def initialize
  @params_doc   = {}
  @examples     = []
  @elements     = []
  @namespaced_params = []
end

Instance Attribute Details

#descObject (readonly)



8
9
10
# File 'lib/documentation.rb', line 8

def desc
  @desc
end

#elementsObject (readonly)



20
21
22
# File 'lib/documentation.rb', line 20

def elements
  @elements
end

#examplesObject (readonly)



17
18
19
# File 'lib/documentation.rb', line 17

def examples
  @examples
end

#namespaced_paramsObject (readonly)



14
15
16
# File 'lib/documentation.rb', line 14

def namespaced_params
  @namespaced_params
end

#params_docObject (readonly)



11
12
13
# File 'lib/documentation.rb', line 11

def params_doc
  @params_doc
end

Instance Method Details

#element(opts = {}) {|ElementDoc| ... } ⇒ Array<ElementDoc>

Add a new element to the doc currently only used for response doc

Parameters:

  • opts (Hash) (defaults to: {})

    element’s documentation options

Yields:

Returns:



144
145
146
147
148
# File 'lib/documentation.rb', line 144

def element(opts={})
  element = ElementDoc.new(opts)
  yield(element)
  @elements << element
end

#example(desc) ⇒ Array<String>

Service usage example

Parameters:

  • desc (String)

    Usage example.

Returns:

  • (Array<String>)

    All the examples.



133
134
135
# File 'lib/documentation.rb', line 133

def example(desc)
  @examples << desc
end

#namespace(ns_name) ⇒ Array Also known as: object

Define a new namespaced param and yield it to the passed block if available.

Returns:

  • (Array)

    the namespaced params



115
116
117
118
119
120
121
# File 'lib/documentation.rb', line 115

def namespace(ns_name)
  new_ns_param = NamespacedParam.new(ns_name)
  if block_given?
    yield(new_ns_param)
  end
  @namespaced_params << new_ns_param
end

#overall(desc) ⇒ String

Sets or returns the overall description

Parameters:

  • desc (String)

    Service overall description

Returns:

  • (String)

    The overall service description



93
94
95
96
97
98
99
# File 'lib/documentation.rb', line 93

def overall(desc)
  if desc.nil?
    @desc
  else 
    @desc = desc
  end
end

#params(name, desc) ⇒ String Also known as: param

Sets the description/documentation of a specific param

Returns:

  • (String)


105
106
107
# File 'lib/documentation.rb', line 105

def params(name, desc)
  @params_doc[name] = desc
end

#responseObject



124
125
126
# File 'lib/documentation.rb', line 124

def response
  @response ||= Documentation.new
end