Class: Snitch::Config

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

Constant Summary collapse

@@snitch_config_path =
'/home/deploy/.snitch'

Class Method Summary collapse

Class Method Details

.config_file_pathObject

Returns the path to the config file.



7
8
9
# File 'lib/snitch/config.rb', line 7

def config_file_path
  @@snitch_config_path
end

.config_file_path=(new_path) ⇒ Object

Allows you to change the config file path.



12
13
14
# File 'lib/snitch/config.rb', line 12

def config_file_path=(new_path)
  @@snitch_config_path = new_path
end

.createObject

Creates a config file based on a template.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/snitch/config.rb', line 27

def create
  snitch_config_tpl = "# what is the location of svnlook (you can find this on *nix boxes by typing `which svnlook`)\nsvnlook: /usr/bin/svnlook\n\n# what services would you like to send commit messages to?\nservices:\n  :campfire:\n    :subdomain: \n    :login: \n    :password: \n    :room: Development\n  :twitter:\n    :login: \n    :password: \n  :email:\n   # You mail server settings:\n    :host:\n    :server: localhost\n    :port: 25\n   # Your login creds:\n    :login:\n    :password:\n    :method: :login\n   # Our email addresses:\n    :from: Snitch <root@localhost>\n    :to:\n"
  File.open(config_file_path, 'w') { |f| f.write snitch_config_tpl } unless File.exists?(config_file_path)
end

.loadObject

Loads the config file. If the file does not exist, it creates it and fills in a blank template that only needs settings.



17
18
19
20
21
22
23
24
# File 'lib/snitch/config.rb', line 17

def load
  begin
    config = YAML::load(open(@@snitch_config_path)).symbolize_keys!
  rescue
    create
    raise ConfigFileLoadError, "The config file was missing or could not be loaded because of a parse error. It should be here: #{@@snitch_config_path}. Fill it out and try again."
  end
end