Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created February 11, 2012 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoward/1796147 to your computer and use it in GitHub Desktop.
Save ahoward/1796147 to your computer and use it in GitHub Desktop.
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|
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