Class: CabbageDoc::Action

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/cabbage_doc/action.rb

Constant Summary collapse

METHODS =
%w(GET POST PUT DELETE).freeze
METHODS_REGEXP =
METHODS.join('|').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

included, #parse_option, #parse_templates

Constructor Details

#initializeAction

Returns a new instance of Action.



10
11
12
13
14
# File 'lib/cabbage_doc/action.rb', line 10

def initialize
  @parameters = []
  @examples = []
  @visibility = VISIBILITY.first
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



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

def visibility
  @visibility
end

Instance Method Details

#param?(key) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/cabbage_doc/action.rb', line 34

def param?(key)
  @parameters.any? { |parameter| parameter.name =~ /#{key}/ }
end

#parse(text, tag = TAG) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cabbage_doc/action.rb', line 16

def parse(text, tag = TAG)
  @method, @path = parse_method_and_path(text)
  return unless valid?

  @name = parse_name(text)
  @label = parse_label(text)
  @description = parse_description(text)
  @visibility = parse_visibility(text)

  @parameters, @examples = parse_parameters_and_examples(text)

  valid?
end

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cabbage_doc/action.rb', line 30

def valid?
  @method && @path
end