Created
February 11, 2012 04:24
-
-
Save ahoward/1796147 to your computer and use it in GitHub Desktop.
cap deployment detection code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this method method will return true if it appears your rail's app is running | |
# in a cap deployment. given a block, it will run that block only if the app | |
# has been deployed via cap | |
# | |
def cap?(&block) | |
realpath = proc do |path| | |
begin | |
(path.is_a?(Pathname) ? path : Pathname.new(path.to_s)).realpath.to_s | |
rescue Errno::ENOENT | |
nil | |
end | |
end | |
rails_root = realpath[Rails.root] | |
shared_path = File.expand_path('../../shared', rails_root) | |
cap_path = File.dirname(shared_path) | |
shared_public_system_path = File.expand_path('../../shared/system') | |
public_path = Rails.public_path.to_s | |
public_system_path = File.join(Rails.public_path.to_s, 'system') | |
is_cap_deploy = | |
test(?e, shared_public_system_path) and | |
test(?l, public_system_path) and | |
realpath[shared_public_system_path] == realpath[public_system_path] | |
return false unless is_cap_deploy | |
block ? block.call(*[cap_path].slice(0, block.arity)) : cap_path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment