Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
cap deployment detection code
# 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|
(path.is_a?(Pathname) ? path :
rescue Errno::ENOENT
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 ?*[cap_path].slice(0, block.arity)) : cap_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment