Class: ScoutApm::DeployIntegrations::Capistrano2
- Inherits:
-
Object
- Object
- ScoutApm::DeployIntegrations::Capistrano2
- Defined in:
- lib/scout_apm/deploy_integrations/capistrano_2.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #branch ⇒ Object
- #current_revision ⇒ Object
- #deploy_data ⇒ Object
- #deployed_by ⇒ Object
- #env ⇒ Object
- #found? ⇒ Boolean
-
#initialize(logger) ⇒ Capistrano2
constructor
A new instance of Capistrano2.
- #install ⇒ Object
- #name ⇒ Object
- #present? ⇒ Boolean
- #report ⇒ Object
- #reporter ⇒ Object
- #root ⇒ Object
- #version ⇒ Object
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
#logger ⇒ Object (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
#branch ⇒ Object
69 70 71 |
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 69 def branch @cap.fetch(:branch) end |
#current_revision ⇒ Object
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_data ⇒ Object
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_by ⇒ Object
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 |
#env ⇒ Object
42 43 44 |
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 42 def env @cap.fetch(:stage) end |
#found? ⇒ Boolean
46 47 48 |
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 46 def found? true end |
#install ⇒ Object
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.("../capistrano_2.cap", __FILE__) end |
#name ⇒ Object
13 14 15 |
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 13 def name :capistrano_2 end |
#present? ⇒ 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 |
#report ⇒ Object
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 |
#reporter ⇒ Object
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 |
#root ⇒ Object
38 39 40 |
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 38 def root '.' end |
#version ⇒ Object
17 18 19 |
# File 'lib/scout_apm/deploy_integrations/capistrano_2.rb', line 17 def version present? ? Capistrano::VERSION : nil end |