Module: Capistrano::Blaze

Extended by:
Blaze
Included in:
Blaze
Defined in:
lib/capistrano/blaze.rb,
lib/capistrano/blaze/version.rb

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#commandObject



53
54
55
# File 'lib/capistrano/blaze.rb', line 53

def command
  [ 'cap', *$* ] * ' '
end

#configure(opts = {}) {|@config| ... } ⇒ Object

Yields:

  • (@config)


11
12
13
14
# File 'lib/capistrano/blaze.rb', line 11

def configure(opts = {})
  @config = OpenStruct.new(opts)
  yield @config if block_given?
end

#failure(context, exception) ⇒ Object



37
38
39
# File 'lib/capistrano/blaze.rb', line 37

def failure(context, exception)
  speak ":warning: #{user} failed to deploy to the #{context.stage} stage of #{context.application}, via `#{command}`: #{exception.to_s} (#{exception.class.inspect})"
end

#speak(message) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/capistrano/blaze.rb', line 16

def speak(message)
  port = @config.ssl ? 443 : 80

  req = Net::HTTP::Post.new("/room/#{@config.room_id}/speak.json")
  req.basic_auth @config.token, 'X'
  req.body = { :message => { :body => message } }.to_json
  req.content_type = "application/json"

  res = Net::HTTP.start("#{@config.}.campfirenow.com", port, :use_ssl => @config.ssl) do |http|
    http.request(req)
  end

  if res.is_a?(Net::HTTPSuccess)
    puts "Campfire message sent!"
  else
    puts "Campfire communication failed!"
    puts res.inspect
    puts res.body.inspect
  end
end

#success(context) ⇒ Object



41
42
43
# File 'lib/capistrano/blaze.rb', line 41

def success(context)
  speak "#{user} succesfully deployed to the #{context.stage} stage of #{context.application}, via `#{command}`"
end

#test(context) ⇒ Object



49
50
51
# File 'lib/capistrano/blaze.rb', line 49

def test(context)
  speak ":heart: #{context.application}!"
end

#userObject



45
46
47
# File 'lib/capistrano/blaze.rb', line 45

def user
  `whoami`.strip
end