public
Created

cap deployment detection code

  • Download Gist
is_cap.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.