Module: Capistrano::Template::Helpers::DSL

Defined in:
lib/capistrano/template/helpers/dsl.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/capistrano/template/helpers/dsl.rb', line 67

def method_missing(method_name, *args)
  if self.class.respond_to? method_name
    self.class.send(method_name, *args)
  else
    super
  end
end

Instance Method Details

#_paths_factoryObject



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

def _paths_factory
  ->(*args) { PathsLookup.new(*args) }
end

#_template_factoryObject



63
64
65
# File 'lib/capistrano/template/helpers/dsl.rb', line 63

def _template_factory
  ->(from, context, digester, locals) {TemplateDigester.new(Renderer.new(from, context, locals: locals), digester) }
end

#_uploader_factoryObject



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

def _uploader_factory
  ->(*args) { Uploader.new(*args) }
end

#dry_run?Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
# File 'lib/capistrano/template/helpers/dsl.rb', line 75

def dry_run?
  if ::Capistrano::Configuration.respond_to?(:dry_run?)
    ::Capistrano::Configuration.dry_run?
  else
    ::Capistrano::Configuration.env.send(:config)[:sshkit_backend] == SSHKit::Backend::Printer
  end
end

#get_to(to, from) ⇒ Object



83
84
85
86
# File 'lib/capistrano/template/helpers/dsl.rb', line 83

def get_to(to, from)
  to ||= "#{release_path}/#{File.basename(from, '.erb')}"
  remote_path_for(to, true)
end

#remote_path_for(path, includes_filename = false) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/capistrano/template/helpers/dsl.rb', line 47

def remote_path_for(path, includes_filename = false)
  filename = nil

  if includes_filename
    filename = File.basename(path)
    path = File.dirname(path)
  end

  cd_cmd = "cd #{path}"
  cd_cmd = "cd #{pwd_path}; #{cd_cmd}" if pwd_path

  remote_path = capture("/bin/bash -c '(#{cd_cmd} && pwd -P) || readlink -sf #{path}'").chomp

  includes_filename ? File.join(remote_path, filename) : remote_path
end

#template(from, to = nil, mode = 0640, user = nil, group = nil, locals: {}) ⇒ Object

rubocop: disable Metrics/AbcSize



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capistrano/template/helpers/dsl.rb', line 6

def template(from, to = nil, mode = 0640, user = nil, group = nil, locals: {})
  fail ::ArgumentError, "template #{from} not found Paths: #{template_paths_lookup.paths_for_file(from).join(':')}" unless template_exists?(from)

  return if dry_run?

  template = _template_factory.call(template_file(from), self, fetch(:templating_digster), locals)

  _uploader_factory.call(get_to(to, from), self,
                         digest: template.digest,
                         digest_cmd: fetch(:templating_digest_cmd),
                         mode_test_cmd: fetch(:templating_mode_test_cmd),
                         user_test_cmd: fetch(:templating_user_test_cmd),
                         group_test_cmd: fetch(:templating_group_test_cmd),
                         mode: mode,
                         user: user,
                         group: group,
                         io: template.as_io
                        ).call
end

#template_exists?(template) ⇒ Boolean

rubocop: enable Metrics/AbcSize

Returns:

  • (Boolean)


27
28
29
# File 'lib/capistrano/template/helpers/dsl.rb', line 27

def template_exists?(template)
  template_paths_lookup.template_exists?(template)
end

#template_file(template) ⇒ Object



31
32
33
# File 'lib/capistrano/template/helpers/dsl.rb', line 31

def template_file(template)
  template_paths_lookup.template_file(template)
end

#template_paths_lookupObject



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

def template_paths_lookup
  _paths_factory.call(fetch(:templating_paths), self)
end