def self.define_task(context, task_method = :task, opts = {})
if defined?(Capistrano) && context.is_a?(Capistrano::Configuration)
context_name = "capistrano"
role_default = "{:except => {:no_release => true}}"
else
context_name = "vlad"
role_default = "[:app]"
end
roles = context.fetch(:bundle_roles, false)
opts[:roles] = roles if roles
context.send :namespace, :bundle do
send :desc, "Install the current Bundler environment. By default, gems will be \\\ninstalled to the shared/bundle path. Gems in the development and \\\ntest group will not be installed. The install command is executed \\\nwith the --deployment and --quiet flags. If the bundle cmd cannot \\\nbe found then you can override the bundle_cmd variable to specifiy \\\nwhich one it should use.\n\nYou can override any of these defaults by setting the variables shown below.\n\nN.B. bundle_roles must be defined before you require 'bundler/\#{context_name}' \\\nin your deploy.rb file.\n\nset :bundle_gemfile, \"Gemfile\"\nset :bundle_dir, File.join(fetch(:shared_path), 'bundle')\nset :bundle_flags, \"--deployment --quiet\"\nset :bundle_without, [:development, :test]\nset :bundle_cmd, \"bundle\" # e.g. \"/opt/ruby/bin/bundle\"\nset :bundle_roles, \#{role_default} # e.g. [:app, :batch]\n"
send task_method, :install, opts do
bundle_cmd = context.fetch(:bundle_cmd, "bundle")
bundle_flags = context.fetch(:bundle_flags, "--deployment --quiet")
bundle_dir = context.fetch(:bundle_dir, File.join(context.fetch(:shared_path), 'bundle'))
bundle_gemfile = context.fetch(:bundle_gemfile, "Gemfile")
bundle_without = [*context.fetch(:bundle_without, [:development, :test])].compact
args = ["--gemfile #{File.join(context.fetch(:current_release), bundle_gemfile)}"]
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
args << bundle_flags.to_s
args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?
run "cd #{context.fetch(:current_release)} && #{bundle_cmd} install #{args.join(' ')}"
end
end
end