lib/capistrano/puma.rb in capistrano3-puma-5.0.4 vs lib/capistrano/puma.rb in capistrano3-puma-5.1.0

- old
+ new

@@ -1,7 +1,7 @@ require 'capistrano/bundler' -require "capistrano/plugin" +require 'capistrano/plugin' module Capistrano module PumaCommon def puma_switch_user(role, &block) user = puma_user(role) @@ -26,12 +26,11 @@ Array(fetch(:puma_bind)).collect do |bind| "bind '#{bind}'" end.join("\n") end - - def template_puma(from, to, role) + 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", @@ -43,10 +42,53 @@ "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) - backend.upload! StringIO.new(ERB.new(erb, nil, '-').result(binding)), to + StringIO.new(ERB.new(erb, nil, '-').result(binding)) + end + + def template_puma(from, to, role) + backend.upload! compiled_template_puma(from, role), to + end + + PumaBind = Struct.new(:full_address, :kind, :address) do + def unix? + kind == :unix + end + + def ssl? + kind == :ssl + end + + def tcp + kind == :tcp || ssl? + end + + def local + if unix? + self + else + PumaBind.new( + localize_address(full_address), + kind, + localize_address(address) + ) + end + end + + private + + def localize_address(address) + address.gsub(/0\.0\.0\.0(.+)/, "127.0.0.1\\1") + end + end + + 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 end class Puma < Capistrano::Plugin include PumaCommon