Class: Debci::SelfDocAPI

Inherits:
App
  • Object
show all
Defined in:
lib/debci/api.rb

Direct Known Subclasses

API

Constant Summary

Constants included from HTMLHelpers

HTMLHelpers::ICONS

Class Method Summary collapse

Methods inherited from App

#allow_browsing?, #authenticate!, #forbidden, #get_page_params, get_page_range, #get_page_range, #logged_in?, #logging_in?, #pagination_params, #refresh!

Methods included from HTMLHelpers

#ansi_to_html, #base_url, #download_url, #expand_pin_packages, #expand_url, #file_link, #history_url, #icon, #javascript_tag, #log_links, #log_url, #notice, notice, #package_url, #pkg_history_url, #static_url, static_url, #stylesheet_tag, #title_test_trigger_pin

Class Method Details

.doc(d = nil) ⇒ Object



25
26
27
28
# File 'lib/debci/api.rb', line 25

def doc(d=nil)
  @last_doc = format_doc(d)
  @doc ||= []
end

.format_doc(text) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/debci/api.rb', line 43

def format_doc(text)
  return nil unless text
  lines = text.lines
  if lines.first && lines.first.strip == ""
    lines.first.shift
  end
  lines.first =~ /^\s+/; prefix = ::Regexp.last_match(0)
  if prefix
    lines.map! do |line|
      line.sub(/^#{prefix}/, '')
    end
  end
  formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
  RDoc::Markdown.parse(lines.join).accept(formatter)
end

.get(path, *args) ⇒ Object



59
60
61
62
# File 'lib/debci/api.rb', line 59

def get(path, *args)
  register_doc('GET', path)
  super
end

.post(path, *args) ⇒ Object



63
64
65
66
# File 'lib/debci/api.rb', line 63

def post(path, *args)
  register_doc('POST', path)
  super
end

.register_doc(method, path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/debci/api.rb', line 30

def register_doc(method, path)
  @last_doc ||= nil
  return unless @last_doc
  entry = {
    method: method,
    path: path,
    text: @last_doc,
    anchor: [method, path].join('_'),
  }
  @last_doc = nil
  doc.push(entry)
end