Class: Baron::Server
- Inherits:
-
Object
- Object
- Baron::Server
- Defined in:
- lib/baron.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(config = {}, &block) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(config = {}, &block) ⇒ Server
Returns a new instance of Server.
33 34 35 36 37 |
# File 'lib/baron.rb', line 33 def initialize config = {}, &block @config = config.is_a?(Config) ? config : Config.new(config) @config.instance_eval(&block) if block_given? @blog_engine = Baron::BlogEngine.new(@config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
31 32 33 |
# File 'lib/baron.rb', line 31 def config @config end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
31 32 33 |
# File 'lib/baron.rb', line 31 def site @site end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/baron.rb', line 39 def call env @request = Rack::Request.new env return [400, {}, []] unless @request.get? @response = Rack::Response.new path, ext = @request.path_info.split('.') extension = ext.to_s.empty? ? '.html' : ".#{ext}" redirected_url, status = @blog_engine.process_redirects(@request.path_info) if status @response.status = status @response['Location'] = redirected_url else = @blog_engine.process_request(@request.path_info, env) @response.body = [[:body]] @response.status = [:status] @response['Content-Length'] = [:body].bytesize.to_s unless [:body].empty? @response['Content-Type'] = Rack::Mime.mime_type(extension) @response['Cache-Control'] = (Baron.env == 'production') ? "public, max-age=#{@config[:cache]}" : "no-cache, must-revalidate" @response['ETag'] = %("#{Digest::SHA1.hexdigest([:body])}") end @response.finish end |