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
SECTION_REGEXP =
"Parameters|Examples|#{METHODS_REGEXP}|#{VISIBILITY_REGEXP}".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.



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

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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



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

def visibility
  @visibility
end

Instance Method Details

#param?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#parse(text, tag = TAG) ⇒ Object



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

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)


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

def valid?
  @method && @path
end