Module: Capistrano::DSL

Includes:
Env, Paths, Stages, TaskEnhancements
Included in:
Configuration::SCMResolver, Plugin
Defined in:
lib/capistrano/dsl.rb,
lib/capistrano/dsl/env.rb,
lib/capistrano/dsl/paths.rb,
lib/capistrano/dsl/stages.rb

Defined Under Namespace

Modules: Env, Paths, Stages

Instance Method Summary collapse

Methods included from Stages

#stage_definitions, #stage_set?, #stages

Methods included from Paths

#asset_timestamp, #current_path, #deploy_config_path, #deploy_path, #deploy_to, #join_paths, #linked_dir_parents, #linked_dirs, #linked_file_dirs, #linked_files, #map_dirnames, #now, #release_path, #releases_path, #repo_path, #repo_url, #revision_log, #set_release_path, #shared_path, #stage_config_path

Methods included from Env

#asset_timestamp, #env, #release_roles, #release_timestamp, #role_properties, #roles

Methods included from TaskEnhancements

#after, #before, #default_tasks, #define_remote_file_task, #deploying?, #ensure_stage, #exit_deploy_because_of_exception, #tasks_without_stage_dependency

Instance Method Details

#executeObject

Catch common beginner mistake and give a helpful error message on stderr

Raises:

  • (NoMethodError)


80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/capistrano/dsl.rb', line 80

def execute(*)
  file, line, = caller.first.split(":")
  colors = SSHKit::Color.new($stderr)
  $stderr.puts colors.colorize("Warning: `execute' should be wrapped in an `on' scope in #{file}:#{line}.", :red)
  $stderr.puts
  $stderr.puts "  task :example do"
  $stderr.puts colors.colorize("    on roles(:app) do", :yellow)
  $stderr.puts "      execute 'whoami'"
  $stderr.puts colors.colorize("    end", :yellow)
  $stderr.puts "  end"
  $stderr.puts
  raise NoMethodError, "undefined method `execute' for main:Object"
end

#invoke(task_name, *args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/capistrano/dsl.rb', line 14

def invoke(task_name, *args)
  task = Rake::Task[task_name]
  # NOTE: We access instance variable since the accessor was only added recently. Once Capistrano depends on rake 11+, we can revert the following line
  if task && task.instance_variable_get(:@already_invoked)
    file, line, = caller.first.split(":")
    colors = SSHKit::Color.new($stderr)
    $stderr.puts colors.colorize("Skipping task `#{task_name}'.", :yellow)
    $stderr.puts "Capistrano tasks may only be invoked once. Since task `#{task}' was previously invoked, invoke(\"#{task_name}\") at #{file}:#{line} will be skipped."
    $stderr.puts "If you really meant to run this task again, use invoke!(\"#{task_name}\")"
    $stderr.puts colors.colorize("THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.", :red)
    $stderr.puts colors.colorize("https://github.com/capistrano/capistrano/issues/1686", :red)
  end
  task.invoke(*args)
end

#invoke!(task_name, *args) ⇒ Object



29
30
31
32
33
# File 'lib/capistrano/dsl.rb', line 29

def invoke!(task_name, *args)
  task = Rake::Task[task_name]
  task.reenable
  task.invoke(*args)
end

#local_userObject



60
61
62
# File 'lib/capistrano/dsl.rb', line 60

def local_user
  fetch(:local_user)
end

#lock(locked_version) ⇒ Object



64
65
66
# File 'lib/capistrano/dsl.rb', line 64

def lock(locked_version)
  VersionValidator.new(locked_version).verify
end

#on(hosts, options = {}, &block) ⇒ Object

rubocop:disable Security/MarshalLoad



69
70
71
72
# File 'lib/capistrano/dsl.rb', line 69

def on(hosts, options={}, &block)
  subset_copy = Marshal.dump(Configuration.env.filter(hosts))
  SSHKit::Coordinator.new(Marshal.load(subset_copy)).each(options, &block)
end

#revision_log_messageObject



47
48
49
50
51
52
53
54
# File 'lib/capistrano/dsl.rb', line 47

def revision_log_message
  fetch(:revision_log_message,
        t(:revision_log_message,
          branch: fetch(:branch),
          user: local_user,
          sha: fetch(:current_revision),
          release: fetch(:release_timestamp)))
end

#rollback_log_messageObject



56
57
58
# File 'lib/capistrano/dsl.rb', line 56

def rollback_log_message
  t(:rollback_log_message, user: local_user, release: fetch(:rollback_timestamp))
end

#run_locally(&block) ⇒ Object

rubocop:enable Security/MarshalLoad



75
76
77
# File 'lib/capistrano/dsl.rb', line 75

def run_locally(&block)
  SSHKit::Backend::Local.new(&block).run
end

#scmObject



39
40
41
# File 'lib/capistrano/dsl.rb', line 39

def scm
  fetch(:scm)
end

#sudo(*args) ⇒ Object



43
44
45
# File 'lib/capistrano/dsl.rb', line 43

def sudo(*args)
  execute :sudo, *args
end

#t(key, options = {}) ⇒ Object



35
36
37
# File 'lib/capistrano/dsl.rb', line 35

def t(key, options={})
  I18n.t(key, options.merge(scope: :capistrano))
end