Class: Rescuetime::Config

Inherits:
Object
  • Object
show all
Includes:
Debug
Defined in:
lib/rescuetime/config.rb

Constant Summary collapse

DEFAULT_PATH =
File.join(Dir.home, ".ruby-rescuetime")
DEFAULT_FILE =
"config.yml"
DEFAULT_CONFIG =
{
  :email    => "[email protected]",
  :password => ""
}

Instance Method Summary collapse

Methods included from Debug

#debug?

Constructor Details

#initialize(options = {}) ⇒ Config

Constructor



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

def initialize(options = {})
  options = {
    :debug    => false,
    :email    => nil,
    :password => nil,
    :config   => File.join(DEFAULT_PATH, DEFAULT_FILE),
    :path     => nil
  }.merge(options)

  debug! if options[:debug]

  @config_path  = options[:config] || File.join(options[:path] || DEFAULT_PATH, DEFAULT_FILE)
  config        = read_config(@config_path)

  @config = {
    :email    => options[:email]    || config[:email],
    :password => options[:password] || config[:password],
    :path     => DEFAULT_PATH       || config[:path]
  }

  update if @config != config
end

Instance Method Details

#emailObject



39
40
41
# File 'lib/rescuetime/config.rb', line 39

def email
  @config[:email]
end

#locationObject



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

def location
  @config_path
end

#passwordObject



43
44
45
# File 'lib/rescuetime/config.rb', line 43

def password
  @config[:password]
end

#pathObject

Path where to store data



48
49
50
# File 'lib/rescuetime/config.rb', line 48

def path
  @config[:path]
end

#updateObject

Write current config to disc



57
58
59
# File 'lib/rescuetime/config.rb', line 57

def update
  update_config(@config, @config_path)
end