Skip to content

Commit

Permalink
Only create the Toto::Site instance once
Browse files Browse the repository at this point in the history
  • Loading branch information
nogweii authored and Alexis Sellier committed Apr 11, 2010
1 parent 0393dfd commit eb87c79
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/toto.rb
Expand Up @@ -311,11 +311,12 @@ def set key, val = nil, &blk
end end


class Server class Server
attr_reader :config attr_reader :config, :site


def initialize config = {}, &blk def initialize config = {}, &blk
@config = config.is_a?(Config) ? config : Config.new(config) @config = config.is_a?(Config) ? config : Config.new(config)
@config.instance_eval(&blk) if block_given? @config.instance_eval(&blk) if block_given?
@site = Toto::Site.new(@config)
end end


def call env def call env
Expand All @@ -327,7 +328,7 @@ def call env
path, mime = @request.path_info.split('.') path, mime = @request.path_info.split('.')
route = (path || '/').split('/').reject {|i| i.empty? } route = (path || '/').split('/').reject {|i| i.empty? }


response = Toto::Site.new(@config).go(route, *(mime ? mime : [])) response = @site.go(route, *(mime ? mime : []))


@response.body = [response[:body]] @response.body = [response[:body]]
@response['Content-Length'] = response[:body].length.to_s unless response[:body].empty? @response['Content-Length'] = response[:body].length.to_s unless response[:body].empty?
Expand Down

0 comments on commit eb87c79

Please sign in to comment.