Class: WSDSL::Documentation

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

Overview

Service documentation class

Since:

  • 0.0.3

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.

Since:

  • 0.0.3



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)

Since:

  • 0.0.3



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

def desc
  @desc
end

#elementsObject (readonly)

Since:

  • 0.0.3



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

def elements
  @elements
end

#examplesObject (readonly)

Since:

  • 0.0.3



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

def examples
  @examples
end

#namespaced_paramsObject (readonly)

Since:

  • 0.0.3



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

def namespaced_params
  @namespaced_params
end

#params_docObject (readonly)

Since:

  • 0.0.3



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:

Since:

  • 0.0.3



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

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.

Since:

  • 0.0.3



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

def example(desc)
  @examples << desc
end

#namespace(ns_name) ⇒ Array

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

Returns:

  • (Array)

    the namespaced params

Since:

  • 0.0.3



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

Since:

  • 0.0.3



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)

Since:

  • 0.0.3



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

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

#responseObject

Since:

  • 0.0.3



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

def response
  @response ||= Documentation.new
end