Class: Bundler::Deployment

Inherits:
Object show all
Defined in:
lib/bundler/deployment.rb

Class Method Summary collapse

Class Method Details

.define_task(context, task_method = :task, opts = {}) ⇒ Object



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bundler/deployment.rb', line 3

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}}"
    error_type = ::Capistrano::CommandError
  else
    context_name = "vlad"
    role_default = "[:app]"
    error_type = ::Rake::CommandFailedError
  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 \\\n      installed to the shared/bundle path. Gems in the development and \\\n      test group will not be installed. The install command is executed \\\n      with the --deployment and --quiet flags. If the bundle cmd cannot \\\n      be found then you can override the bundle_cmd variable to specifiy \\\n      which one it should use.\n\n      You can override any of these defaults by setting the variables shown below.\n\n      N.B. bundle_roles must be defined before you require 'bundler/\#{context_name}' \\\n      in your deploy.rb file.\n\n        set :bundle_gemfile,  \"Gemfile\"\n        set :bundle_dir,      File.join(fetch(:shared_path), 'bundle')\n        set :bundle_flags,    \"--deployment --quiet\"\n        set :bundle_without,  [:development, :test]\n        set :bundle_cmd,      \"bundle\" # e.g. \"/opt/ruby/bin/bundle\"\n        set :bundle_roles,    \#{role_default} # e.g. [:app, :batch]\n    DESC\n    send task_method, :install, opts do\n      bundle_cmd     = context.fetch(:bundle_cmd, \"bundle\")\n      bundle_flags   = context.fetch(:bundle_flags, \"--deployment --quiet\")\n      bundle_dir     = context.fetch(:bundle_dir, File.join(context.fetch(:shared_path), 'bundle'))\n      bundle_gemfile = context.fetch(:bundle_gemfile, \"Gemfile\")\n      bundle_without = [*context.fetch(:bundle_without, [:development, :test])].compact\n      current_release = context.fetch(:current_release)\n      if current_release.to_s.empty?\n        raise error_type.new(\"Cannot detect current release path - make sure you have deployed at least once.\")\n      end\n      args = [\"--gemfile \#{File.join(current_release, bundle_gemfile)}\"]\n      args << \"--path \#{bundle_dir}\" unless bundle_dir.to_s.empty?\n      args << bundle_flags.to_s\n      args << \"--without \#{bundle_without.join(\" \")}\" unless bundle_without.empty?\n\n      run \"cd \#{current_release} && \#{bundle_cmd} install \#{args.join(' ')}\"\n    end\n  end\nend\n"