Class: SelfDocAPI

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

Direct Known Subclasses

Debci::API

Class Method Summary collapse

Class Method Details

.doc(d = nil) ⇒ Object



21
22
23
24
# File 'lib/debci/api.rb', line 21

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

.format_doc(text) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/debci/api.rb', line 35

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 = $&
  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



51
52
53
54
# File 'lib/debci/api.rb', line 51

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

.post(path, *args) ⇒ Object



55
56
57
58
# File 'lib/debci/api.rb', line 55

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

.register_doc(method, path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/debci/api.rb', line 25

def register_doc(method, path)
  return unless @last_doc
  entry = {
    :method => method,
    :path => path,
    :text => @last_doc
  }
  @last_doc = nil
  doc.push(entry)
end