Class: Capfire

Inherits:
Object
  • Object
show all
Defined in:
lib/capfire.rb

Class Method Summary collapse

Class Method Details

.accountObject

Campfire account



29
30
31
# File 'lib/capfire.rb', line 29

def 
  self.config["account"]
end

.bin_installed?(bin_name) ⇒ Boolean

Quick and irty way to check for installed bins Ideally this should also check if it’s in the users path etc. Skipping for now.

Returns:

  • (Boolean)


90
91
92
# File 'lib/capfire.rb', line 90

def bin_installed?(bin_name)
  !`which #{bin_name}`.empty?
end

.broach_roomObject

Initializes a broach campfire room



95
96
97
98
99
100
101
102
# File 'lib/capfire.rb', line 95

def broach_room
  Broach.settings = {
    'account' => self.,
    'token' => self.token,
    'use_ssl' => true
  }
  Broach::Room.find_by_name(self.room)
end

.configObject



19
20
21
# File 'lib/capfire.rb', line 19

def config
  YAML::load(File.open(File.join(ENV['HOME'],'.campfire')))["campfire"]
end

.config_file_exists?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/capfire.rb', line 10

def config_file_exists?
  File.exists?(File.join(ENV['HOME'],'.campfire'))
end

.cowsay?Boolean

‘brew install cowsay && cowsay “capfire”`

_________

< capfire >


\   ^__^
 \  (oo)\_______
    (__)\       )\/\
        ||----w |
        ||     ||

Returns:

  • (Boolean)


47
48
49
# File 'lib/capfire.rb', line 47

def cowsay?
  config["cowsay"] && self.bin_installed?("cowsay")
end

.default_idiot_messageObject



64
65
66
# File 'lib/capfire.rb', line 64

def default_idiot_message
  "LATFH: #deployer# wanted to deploy #application#, but forgot to push first."
end

.deploy_message(args, compare_url, application) ⇒ Object

Message to post to campfire on deploy



78
79
80
81
82
83
84
85
# File 'lib/capfire.rb', line 78

def deploy_message(args,compare_url, application)
  message = self.config["message"]
  message.gsub!(/#deployer#/, deployer)
  message.gsub!(/#application#/, application)
  message.gsub!(/#args#/, args)
  message.gsub!(/#compare_url#/, compare_url)
  message
end

.deployerObject

Who is deploying



52
53
54
# File 'lib/capfire.rb', line 52

def deployer
  Etc.getlogin
end

.github_compare_url(repo_url, first_commit, last_commit) ⇒ Object

Link to github’s excellent Compare View



57
58
59
60
61
62
# File 'lib/capfire.rb', line 57

def github_compare_url(repo_url, first_commit, last_commit)
  repo_url.gsub!(/git@/, 'http://')
  repo_url.gsub!(/\.com:/,'.com/')
  repo_url.gsub!(/\.git/, '')
  "#{repo_url}/compare/#{first_commit}...#{last_commit}"
end

.idiot_message(application) ⇒ Object

Message to post on deploying without pushing



69
70
71
72
73
74
75
# File 'lib/capfire.rb', line 69

def idiot_message(application)
  message = self.config["idiot_message"]
  message = default_idiot_message unless message
  message.gsub!(/#deployer#/, self.deployer)
  message.gsub!(/#application#/, application)
  message
end

.roomObject

Campfire room



24
25
26
# File 'lib/capfire.rb', line 24

def room
  self.config["room"]
end

.speak(message) ⇒ Object

Posts to campfire



105
106
107
# File 'lib/capfire.rb', line 105

def speak(message)
  self.broach_room.speak(message)
end

.tokenObject

Campfire token



34
35
36
# File 'lib/capfire.rb', line 34

def token
  self.config["token"]
end

.valid_config?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/capfire.rb', line 14

def valid_config?
  config = self.config
  config["message"] && config["room"] && config ["token"] && config["account"]
end