Class: ScoutApm::DeployIntegrations::Capistrano3

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/deploy_integrations/capistrano_3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Capistrano3

Returns a new instance of Capistrano3.



8
9
10
11
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 8

def initialize(logger)
  @logger = logger
  @cap = Rake.application rescue nil
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 6

def logger
  @logger
end

Instance Method Details

#branchObject



68
69
70
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 68

def branch
  @cap.fetch(:branch)
end

#current_revisionObject



72
73
74
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 72

def current_revision
  @cap.fetch(:current_revision) || `git rev-list --max-count=1 --abbrev-commit --abbrev=12 #{branch}`.chomp
end

#deploy_dataObject



64
65
66
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 64

def deploy_data
  {:revision => current_revision, :branch => branch, :deployed_by => deployed_by}
end

#deployed_byObject



76
77
78
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 76

def deployed_by
  ScoutApm::Agent.instance.config.value('deployed_by')
end

#envObject



41
42
43
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 41

def env
  @cap.fetch(:stage).to_s
end

#found?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 45

def found?
  true
end

#installObject



32
33
34
35
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 32

def install
  logger.debug "Initializing Capistrano3 Deploy Integration."
  load File.expand_path("../capistrano_3.cap", __FILE__)
end

#nameObject



13
14
15
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 13

def name
  :capistrano_3
end

#present?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 21

def present?
  if !@cap.nil? && @cap.is_a?(Capistrano::Application)
    require 'capistrano/version'
    defined?(Capistrano::VERSION) && Gem::Dependency.new('', '~> 3.0').match?('', Capistrano::VERSION.to_s)
  else
    return false
  end
rescue
  return false
end

#reportObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 49

def report
  if reporter.can_report?
    data = deploy_data
    logger.debug "Sending deploy hook data: #{data}"
    payload = ScoutApm::Serializers::DeploySerializer.serialize(data)
    reporter.report(payload, ScoutApm::Serializers::DeploySerializer::HTTP_HEADERS)
  else
    logger.warn "Unable to post deploy hook data"
  end
end

#reporterObject



60
61
62
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 60

def reporter
  @reporter ||= ScoutApm::Reporter.new(:deploy_hook, ScoutApm::Agent.instance.config, @logger)
end

#rootObject



37
38
39
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 37

def root
  '.'
end

#versionObject



17
18
19
# File 'lib/scout_apm/deploy_integrations/capistrano_3.rb', line 17

def version
  present? ? Capistrano::VERSION : nil
end