5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
|
# File 'lib/web_tools/support/service_helper.rb', line 5
def self.included(base)
base.set :show_exceptions, false
base.set :raise_errors, false
base.set :method_override, true
base.set :logging, true
base.use Rack::JSONP
base.error do
excep = request.env['sinatra.error']
puts
p excep.message
puts excep.backtrace
json('_stack' => excep.backtrace.join("<br>"),
'_error' => excep.message)
end
base.before do
@ts = Time.now
end
base.helpers do
def non_meta_name(str)
if str =~ /^#<Class:.*>$/
str["#<Class:".length..-2]
else
str
end
end
def json(obj)
content_type :json
obj.to_hash.tap do |o|
o["_time"] = ((Time.now - @ts) * 1000).to_i
end.to_json
end
def reflect(obj)
system.reflect(obj)
end
def system
@reflection ||= MirrorAPI::Reflection.new
end
end
end
|