Permalink
Browse files

separate app creation from app running

  • Loading branch information...
1 parent e3e1891 commit eaf286c7f4c4096b0030aba41832ca09e7ae83cf Josh Hull committed Jan 16, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/apiary.rb
View
@@ -45,8 +45,7 @@ def default_path(m)
end
end
- def run(port = 3000, &blk)
- raise "No version specified" unless @version
+ def __as_app(&blk)
router = HttpRouter.new
@cmds.each do |cmd|
path = "#{@version}/#{cmd.path || default_path(cmd.method)}".squeeze('/')
@@ -56,8 +55,14 @@ def run(port = 3000, &blk)
Rack::Response.new((blk ? blk.call : new).send(cmd.method, *env['router.response'].param_values).to_s).finish
}
end
+ router
+ end
+
+ def run(port = 3000, &blk)
+ api = self
+ raise "No version specified" unless @version
Thin::Server.new('0.0.0.0', port) {
- run router
+ run api.__as_app(&blk)
}.start
end
end

0 comments on commit eaf286c

Please sign in to comment.