Class: VirtualServer
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- VirtualServer
- Defined in:
- lib/file_sv/virtual_server.rb
Overview
Virtual server hosting virtual service defined through files
Instance Method Summary collapse
- #append_content_type(endpoint) ⇒ Object
-
#output_for(endpoint, binding) ⇒ Object
Output for endpoint, either a file or text content.
-
#serve(endpoint, id = nil) ⇒ Object
Log endpoint.
Instance Method Details
#append_content_type(endpoint) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/file_sv/virtual_server.rb', line 43 def append_content_type(endpoint) if endpoint.file_path.end_with? ".json" content_type :json elsif endpoint.file_path.end_with? ".xml" content_type :xml elsif endpoint.file_path.end_with? ".css" content_type :css elsif endpoint.file_path.end_with? ".js" content_type :js end end |
#output_for(endpoint, binding) ⇒ Object
Output for endpoint, either a file or text content
39 40 41 |
# File 'lib/file_sv/virtual_server.rb', line 39 def output_for(endpoint, binding) endpoint.file? ? send_file(endpoint.serving_file_name) : endpoint.content(binding) end |
#serve(endpoint, id = nil) ⇒ Object
Log endpoint. Return content and status code defined by endpoint
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/file_sv/virtual_server.rb', line 57 def serve(endpoint, id = nil) @id = id append_content_type(endpoint) if ENV["debug"] == "true" = "Using endpoint based on file #{endpoint.serving_file_name}." += " Using param '#{@id}'" if id FileSv.logger.debug end sleep endpoint.delay if endpoint.delay > 0 [endpoint.status_code, output_for(endpoint, binding)] end |