Module: AvroTurf::Test::FakeServer::InstanceMethods
- Defined in:
- lib/avro_turf/test/fake_server.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#halt(status, body) ⇒ Object
Early return from a route handler with a specific status and body.
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
105 106 107 |
# File 'lib/avro_turf/test/fake_server.rb', line 105 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
105 106 107 |
# File 'lib/avro_turf/test/fake_server.rb', line 105 def request @request end |
Instance Method Details
#call(env) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/avro_turf/test/fake_server.rb', line 107 def call(env) @request = Rack::Request.new(env) @params = {} # Check host authorization if configured if (auth = self.class.) permitted = auth[:permitted_hosts] || [] unless permitted.include?(@request.host) return [403, {"Content-Type" => "text/plain"}, ["Forbidden"]] end end # Use catch/throw for halt mechanism (like Sinatra) catch(:halt) do route_and_dispatch(env) end end |
#halt(status, body) ⇒ Object
Early return from a route handler with a specific status and body
126 127 128 |
# File 'lib/avro_turf/test/fake_server.rb', line 126 def halt(status, body) throw :halt, [status, {"Content-Type" => "application/json"}, [body]] end |