Module: ProcessBot::Capistrano::Puma::Common

Included in:
ProcessBot::Capistrano::Puma
Defined in:
lib/process_bot/capistrano/puma/common.rb

Defined Under Namespace

Classes: PumaBind

Instance Method Summary collapse

Instance Method Details

#compiled_template_puma(from, role) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/process_bot/capistrano/puma/common.rb', line 25

def compiled_template_puma(from, role)
  @role = role
  file = [
    "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
    "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
    "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
    "lib/capistrano/templates/#{from}.rb.erb",
    "lib/capistrano/templates/#{from}.rb",
    "lib/capistrano/templates/#{from}.erb",
    "config/deploy/templates/#{from}.rb.erb",
    "config/deploy/templates/#{from}.rb",
    "config/deploy/templates/#{from}.erb",
    File.expand_path("../templates/#{from}.erb", __FILE__),
    File.expand_path("../templates/#{from}.rb.erb", __FILE__)
  ].detect { |path| File.file?(path) }
  erb = File.read(file)
  StringIO.new(ERB.new(erb, trim_mode: "-").result(binding))
end

#puma_bindObject



19
20
21
22
23
# File 'lib/process_bot/capistrano/puma/common.rb', line 19

def puma_bind
  Array(fetch(:puma_bind)).collect do |bind|
    "bind '#{bind}'"
  end.join("\n")
end

#puma_bindsObject



80
81
82
83
84
85
# File 'lib/process_bot/capistrano/puma/common.rb', line 80

def puma_binds
  Array(fetch(:puma_bind)).map do |m|
    etype, address  = /(tcp|unix|ssl):\/{1,2}(.+)/.match(m).captures
    PumaBind.new(m, etype.to_sym, address)
  end
end

#puma_switch_user(role) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/process_bot/capistrano/puma/common.rb', line 2

def puma_switch_user(role)
  user = puma_user(role)
  if user == role.user
    yield
  else
    backend.as user, &block
  end
end

#puma_user(role) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/process_bot/capistrano/puma/common.rb', line 11

def puma_user(role)
  properties = role.properties
  properties.fetch(:puma_user) || # local property for puma only
    fetch(:puma_user) ||
    properties.fetch(:run_as) || # global property across multiple capistrano gems
    role.user
end

#template_puma(from, to, role) ⇒ Object



44
45
46
# File 'lib/process_bot/capistrano/puma/common.rb', line 44

def template_puma(from, to, role)
  backend.upload! compiled_template_puma(from, role), to
end