Class: ScoutApm::DeployIntegrations::Capistrano2

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Capistrano2

Returns a new instance of Capistrano2.



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

def initialize(logger)
  @logger = logger
  @cap = defined?(Capistrano::Configuration) ? ObjectSpace.each_object(Capistrano::Configuration).map.first : nil rescue nil
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

Instance Method Details

#branchObject



69
70
71
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 69

def branch
  @cap.fetch(:branch)
end

#current_revisionObject



73
74
75
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 73

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

#deploy_dataObject



65
66
67
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 65

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

#deployed_byObject



77
78
79
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 77

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

#envObject



42
43
44
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 42

def env
  @cap.fetch(:stage)
end

#found?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 46

def found?
  true
end

#installObject



33
34
35
36
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 33

def install
  logger.debug "Initializing Capistrano2 Deploy Integration."
  @cap.load File.expand_path("../capistrano_2.cap", __FILE__)
end

#nameObject



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

def name
  :capistrano_2
end

#present?Boolean

Returns:

  • (Boolean)


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

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

#reportObject



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

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



61
62
63
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 61

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

#rootObject



38
39
40
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 38

def root
  '.'
end

#versionObject



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

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