Skip to content

Commit 8738469

Browse files
committed
root_path doesn't always do the right thing.
This fix is a bit of a hack. If we haven't exeuted the runner (ie, we're parsing the file) then we haven't chdir'd to the API directory, which means we need a different meaning for root_path. This fix adds an app_path method which can be used prior to the chdir. Root_path can be used after the chdir. Like I said, hack. Can't think of a better way to handle this at the moment without storing a global specifying if we've changed directories or not. Fixespostrank-labs#40.
1 parent a757b84 commit 8738469

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

‎examples/template.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class Template < Goliath::API
2424
includeGoliath::Rack::Templates# render templated files from ./views
2525

2626
use(Rack::Static,# render static files from ./public
27-
:root=>Goliath::Application.root_path("public"),
27+
:root=>Goliath::Application.app_path("public"),
2828
:urls=>["/favicon.ico",'/stylesheets','/javascripts','/images'])
29+
2930
pluginGoliath::Plugin::Latency# ask eventmachine reactor to track its latency
3031

3132
defrecent_latency

‎lib/goliath/application.rb‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class Application
88

99
# Set of caller regex's to be skipped when looking for our API file
1010
CALLERS_TO_IGNORE=[# :nodoc:
11-
/\/goliath(\/(application))?\.rb$/,# all goliath code
11+
/\/goliath(\/application)?\.rb$/,# all goliath code
12+
/\/goliath(\/(rack|validation|plugins)\/)/,# all goliath code
1213
/rubygems\/custom_require\.rb$/,# rubygems require hacks
1314
/bundler(\/runtime)?\.rb/,# bundler require hacks
1415
/<internal:/# internal in ruby >= 1.9.2
@@ -40,12 +41,27 @@ def self.app_file
4041
c
4142
end
4243

44+
# Retrive the base director for the API before we've changed directories
45+
#
46+
# @note Note sure of a better way to handle this. Goliath will do a chdir
47+
# when the runner is executed. If you need the +root_path+ before
48+
# the runner is executing (like, in a use statement) you need this method.
49+
#
50+
# @param args [Array] Any arguments to append to the path
51+
# @return [String] path for the given arguments
52+
defself.app_path(*args)
53+
@app_path ||= File.expand_path(File.dirname(app_file))
54+
File.join(@app_path, *args)
55+
end
56+
4357
# Retrieve the base directory for the API
4458
#
4559
# @param args [Array] Any arguments to append to the path
46-
# @return [File] path for the given arguments
60+
# @return [String] path for the given arguments
4761
defself.root_path(*args)
48-
@root_path ||= File.expand_path(File.dirname(app_file))
62+
returnapp_path(args)ifGoliath.test?
63+
64+
@root_path ||= File.expand_path("./")
4965
File.join(@root_path, *args)
5066
end
5167

0 commit comments

Comments
(0)