Class: Yarddown::Endpoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yardoc) ⇒ Endpoint

Returns a new instance of Endpoint.



16
17
18
19
# File 'lib/yardbird/endpoint.rb', line 16

def initialize(yardoc)
  @yardoc = yardoc
  parse
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def category
  @category
end

#docstringObject

Returns the value of attribute docstring.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def docstring
  @docstring
end

#exampleObject

Returns the value of attribute example.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def example
  @example
end

#example_paramsObject

Returns the value of attribute example_params.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def example_params
  @example_params
end

#methodObject

Returns the value of attribute method.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def method
  @method
end

#paramsObject

Returns the value of attribute params.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def params
  @params
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def path
  @path
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/yardbird/endpoint.rb', line 7

def status
  @status
end

Instance Method Details

#doc_pathObject



55
56
57
# File 'lib/yardbird/endpoint.rb', line 55

def doc_path
  "#{path}.#{method}"
end

#parseObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yardbird/endpoint.rb', line 21

def parse
  self.method = @yardoc.tags(:http)[0].try(:text)
  self.method ||= 'GET'

  self.path   = @yardoc.tags(:path)[0].try(:text)
  self.docstring = @yardoc.docstring
  if @yardoc.tags(:category).any?
    self.category = @yardoc.tags(:category)[0].try(:text)
  else
    self.category = 'Uncategorized'
  end
  self.status = @yardoc.tags(:status).map do |s|
    {
      code: s.name.to_i,
      doc: s.text
    }
  end
  self.status = self.status.sort_by { |s| s[:code] }
  self.params = [@yardoc.tags(:required), @yardoc.tags(:optional)].flatten.map do |param|
    {
      name: param.name,
      types: param.types,
      doc: param.text,
      type: param.tag_name
    }
  end

  self.example = @yardoc.tags(:example)[0].try(:name)
  self.example ||= self.path
  if @yardoc.tags(:example)[0].try(:text)
    self.example_params = @yardoc.tags(:example)[0].text.split.map {|p| p.split(':')}
  end
end