Module: Dickburt::Config

Defined in:
lib/dickburt/config.rb

Class Method Summary collapse

Class Method Details

.configObject

Reads the config, or gives you an empty hash.



34
35
36
37
# File 'lib/dickburt/config.rb', line 34

def config
  ensure_config_exists
  @config ||= (YAML.load_file(config_file) || {})
end

.config_hash(host, room) ⇒ Object

Provides a nice config hash that we build up from the command line to hand off to Dickburt::Server. This is only ever called bin/dickburt. That script raises errors for missing host and room, so its a bit redundant redundant to check that here.



14
15
16
17
18
19
20
21
22
# File 'lib/dickburt/config.rb', line 14

def config_hash(host, room)
  token = config[host.to_sym][:token] if config[host.to_sym]
  unless token
    raise Dickburt::Error, "You need to provide an api token.\n Just add: --token yourtokenfromcampfire to the command line args.\n The token will get stored in ~/.dickburt/config.yml for next time so you don't have to remember it"
  end
  { host:   host, 
    token:  token, 
    room:   room.downcase.gsub(/\s/,'_') }
end

.set_token(host, token = nil) ⇒ Object

Public: Stores the given token for the given host. Will not raise an error if the token is not given, leaves that up to bin/dickburt.



26
27
28
29
30
31
# File 'lib/dickburt/config.rb', line 26

def set_token(host, token=nil)
  if token
    config[host.to_sym] = {:token => token}
    write
  end
end