Class: Rascut::Asdoc::Httpd
- Inherits:
-
Object
- Object
- Rascut::Asdoc::Httpd
show all
- Includes:
- Utils
- Defined in:
- lib/rascut/asdoc/httpd.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
asdoc_home, home, path_escape, rascut_db, rascut_db_path, rascut_db_read
Constructor Details
#initialize ⇒ Httpd
Returns a new instance of Httpd.
17
18
19
20
21
|
# File 'lib/rascut/asdoc/httpd.rb', line 17
def initialize
@logger = Logger.new(STDOUT)
@threads = []
@data = Rascut::Asdoc::Data.asdoc_data
end
|
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
22
23
24
|
# File 'lib/rascut/asdoc/httpd.rb', line 22
def command
@command
end
|
#data ⇒ Object
Returns the value of attribute data.
34
35
36
|
# File 'lib/rascut/asdoc/httpd.rb', line 34
def data
@data
end
|
Instance Method Details
#config ⇒ Object
108
109
110
111
|
# File 'lib/rascut/asdoc/httpd.rb', line 108
def config
{}
end
|
#json_handler ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rascut/asdoc/httpd.rb', line 36
def json_handler
ProcHandler.new do |req, res|
ary = []
params = Mongrel::HttpRequest.query_parse(req.params['QUERY_STRING'])
if word = params['word']
method_re, class_re, package_re = *search_regexes(word.strip)
c = 0
if method_re
@data[:methods].each do |i|
if i[:name].match method_re
next if class_re && !i[:classname].match(class_re)
next if package_re && !i[:package].match(package_re)
ary << i
c += 1
break if c >= 20
end
end
elsif class_re
@data[:classes].each do |i|
if i[:classname].match class_re
next if package_re && !i[:package].match(package_re)
ary << i
c += 1
break if c >= 20
end
end
elsif package_re
@data[:packages].each do |i|
if i[:package].match package_re
ary << i
c += 1
break if c >= 20
end
end
end
end
res.start do |head, out|
head['Content-Type'] = 'application/json'
out << ary.to_json
end
end
end
|
#logger ⇒ Object
113
114
115
|
# File 'lib/rascut/asdoc/httpd.rb', line 113
def logger
@logger
end
|
#run ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rascut/asdoc/httpd.rb', line 24
def run
port = config[:port] || 3002
host = config[:bind_address] || '0.0.0.0'
@http_server = Mongrel::HttpServer.new(host, port)
@http_server.register('/', Mongrel::DirHandler.new(asdoc_home.to_s))
@http_server.register('/json', json_handler)
@http_server.run
logger.info "Start Mongrel: http://#{host}:#{port}/"
end
|
#search_regexes(w) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/rascut/asdoc/httpd.rb', line 81
def search_regexes(w)
method_re = class_re = package_re = nil
words = w.split(/\s+/)
words.each do |word|
case word[0..0]
when '.'
package_re = /#{Regexp.escape(word[1..-1])}/
when /[A-Z]/
class_re = /#{Regexp.escape(word)}/
else
method_re = /^#{Regexp.escape(word.sub('#', ''))}/
end
end
[method_re, class_re, package_re]
end
|
#stop ⇒ Object
103
104
105
106
|
# File 'lib/rascut/asdoc/httpd.rb', line 103
def stop
end
|