Class: Ruined::DebugServlet

Inherits:
HTTPServlet::AbstractServlet
  • Object
show all
Includes:
WEBrick::HTMLUtils
Defined in:
lib/ruined/ruinmain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request


98
99
100
# File 'lib/ruined/ruinmain.rb', line 98

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response


98
99
100
# File 'lib/ruined/ruinmain.rb', line 98

def response
  @response
end

Instance Method Details

#break(*a) ⇒ Object


100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ruined/ruinmain.rb', line 100

def break(*a)
  if a.size < 3
    bye(response)
  else
    point = [a[1..(a.size - 2)].join('/'), a[a.size - 1].to_i]
    if a[0] == 'true'
      Ruined.breakpoints << point
    else
      Ruined.breakpoints.delete point
    end
    JSON(point)
  end
end

#cont(*a) ⇒ Object


125
126
127
128
129
# File 'lib/ruined/ruinmain.rb', line 125

def cont(*a)
  Ruined.release 0
  Ruined.wait 1
  JSON(Ruined.current_context)
end

#do_GET(req, res) ⇒ Object


81
82
83
84
85
86
87
88
# File 'lib/ruined/ruinmain.rb', line 81

def do_GET(req, res)
  m = %r|/debug/([^/?]+)/?([^?]*).*\Z|.match(req.unparsed_uri)
  if m
    res.body = __send__(m[1].to_sym, *(m[2].split('/').map{|x|URI.decode(x)}))
  else
    bye(res)        
  end
end

#do_POST(req, res) ⇒ Object


89
90
91
92
93
94
95
96
# File 'lib/ruined/ruinmain.rb', line 89

def do_POST(req, res)
  m = %r|/debug/([^/?]+)/?([^?]*).*\Z|.match(req.unparsed_uri)
  if m && m[1] == 'file'
    res.body = __send__(m[1].to_sym, *(m[2].split('/').map{|x|URI.decode(x)}))
  else
    bye(res)        
  end
end

#file(*a) ⇒ Object


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ruined/ruinmain.rb', line 135

def file(*a)
  file = a.join('/')
  if request.request_method == 'GET'
    request.accept.each do |accept|
      if accept =~ /html/i
        break
      elsif accept =~ %r|text/plain|i
        File.open(file) do |f|
          return Ruined::to_utf8(f.read)
        end
      end
    end
    to_html(file)
  else
    # TODO: newline and charset justify
    # wb is workaround for inhibit to put addition \r
    File.open("#{file}.new", 'wb') do |f|
      f.write(request.body)
    end
    FileUtils.cp file, "#{file}.bak", :verbose => true
    FileUtils.cp "#{file}.new", file, :verbose => true
    FileUtils.rm "#{file}.new"
    "save #{file}"
  end  
end

#globals(*a) ⇒ Object


169
170
171
172
173
174
175
# File 'lib/ruined/ruinmain.rb', line 169

def globals(*a)
  if a.size == 0
    create_varlist Ruined.global_vars
  else
    eval_var(a)
  end
end

#locals(*a) ⇒ Object


161
162
163
164
165
166
167
# File 'lib/ruined/ruinmain.rb', line 161

def locals(*a)
  if a.size == 0
    create_varlist Ruined.local_vars
  else
    eval_var(a)
  end
end

#run(*a) ⇒ Object


114
115
# File 'lib/ruined/ruinmain.rb', line 114

def run(*a)
end

#self(*a) ⇒ Object


177
178
179
180
181
182
183
184
185
# File 'lib/ruined/ruinmain.rb', line 177

def self(*a)
  if a.size == 0
    create_varlist Ruined.self_vars
  elsif a.size < 2
    bye(response)
  else
    eval_var(a)
  end
end

#service(req, res) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ruined/ruinmain.rb', line 70

def service(req, res)
  if Ruined.local_call?(req.addr)
    @response = res
    @request = req
    super
    @response = nil
    @request = nil
  else
    bye(res)
  end
end

#start(*a) ⇒ Object


187
188
189
# File 'lib/ruined/ruinmain.rb', line 187

def start(*a)
  '<html>start</html>'
end

#step(*a) ⇒ Object


131
132
133
# File 'lib/ruined/ruinmain.rb', line 131

def step(*a)
  cont(a)
end

#stepping(*a) ⇒ Object


120
121
122
123
# File 'lib/ruined/ruinmain.rb', line 120

def stepping(*a)
  Ruined.wait 1      
  JSON(Ruined.current_context)
end

#stop(*a) ⇒ Object


117
118
# File 'lib/ruined/ruinmain.rb', line 117

def stop(*a)
end