Class: YNTask
- Inherits:
-
Object
- Object
- YNTask
- Defined in:
- lib/yn_task.rb
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize(request) ⇒ YNTask
constructor
A new instance of YNTask.
- #method_missing(method_name) ⇒ Object
-
#say_hello ⇒ Object
route: /RubyServer/hello.
-
#test_json ⇒ Object
route: /RubyServer/json.
Constructor Details
#initialize(request) ⇒ YNTask
Returns a new instance of YNTask.
6 7 8 |
# File 'lib/yn_task.rb', line 6 def initialize(request) @request = request end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
10 11 12 13 |
# File 'lib/yn_task.rb', line 10 def method_missing(method_name) puts "#{method_name} not found in YNTask,please check yn_route_uril.rb" default end |
Instance Method Details
#default ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/yn_task.rb', line 43 def default http = YNHttp.new http.content_type = "text/html" http.status = 404 http.body = "<html><head><title>Welcome</title></html><body><h1>Welcome to Yan's ruby server!</h1><p><h3>404 Not Found</h3></p></body></html>" http.response end |
#say_hello ⇒ Object
route: /RubyServer/hello
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yn_task.rb', line 16 def say_hello begin http = YNHttp.new http.content_type = "text/html" _param = "" @request.each do |e| _param+="#{e[0]}=#{e[1]}<br>" end http.body = "<html><head><title>Hello to Ruby Server</title></html><body><h1>Hi,welcome to Yan's ruby server!</h1><p>the request param:<br>#{_param}</p></body></html>" # return the response result http.response rescue Exception => e puts e.send(:caller) end end |
#test_json ⇒ Object
route: /RubyServer/json
35 36 37 38 39 40 41 |
# File 'lib/yn_task.rb', line 35 def test_json http = YNHttp.new http.content_type = "text/json" result = JSON.generate(@request.hash) http.body = result http.response end |