Class: Mockingbird::ScriptRunner
- Inherits:
-
Object
- Object
- Mockingbird::ScriptRunner
- Defined in:
- lib/mockingbird/script_runner.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
-
#script ⇒ Object
Returns the value of attribute script.
Instance Method Summary collapse
-
#initialize(conn, script) ⇒ ScriptRunner
constructor
A new instance of ScriptRunner.
- #run ⇒ Object
- #send_body ⇒ Object
- #send_headers ⇒ Object
- #send_status ⇒ Object
Constructor Details
#initialize(conn, script) ⇒ ScriptRunner
Returns a new instance of ScriptRunner.
7 8 9 10 |
# File 'lib/mockingbird/script_runner.rb', line 7 def initialize(conn,script) self.conn = conn self.script = script end |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
5 6 7 |
# File 'lib/mockingbird/script_runner.rb', line 5 def conn @conn end |
#script ⇒ Object
Returns the value of attribute script.
5 6 7 |
# File 'lib/mockingbird/script_runner.rb', line 5 def script @script end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 |
# File 'lib/mockingbird/script_runner.rb', line 12 def run send_status send_headers send_body end |
#send_body ⇒ Object
34 35 36 37 |
# File 'lib/mockingbird/script_runner.rb', line 34 def send_body conn.start_body script.body.run(conn) end |
#send_headers ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mockingbird/script_runner.rb', line 23 def send_headers headers = { "Transfer-Encoding"=>"chunked", "Content-Type"=>"application/json", "Server"=>"Mockingbird" }.merge(script.headers||{}) headers.each do |name, value| conn.send_header(name, value) end end |
#send_status ⇒ Object
18 19 20 21 |
# File 'lib/mockingbird/script_runner.rb', line 18 def send_status code, = (script.status || [200,"OK"]) conn.send_status(code,) end |