Class: Redmine::Config

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

Constant Summary collapse

DEFAULT_PATH =
File.join(Dir.home, ".redmine")
DEFAULT_FILE =
"config.yml"
DEFAULT_CONFIG =
{
  :key => nil
}

Instance Method Summary collapse

Methods included from Debug

#debug?

Constructor Details

#initialize(options = {}) ⇒ Config

Constructor



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

def initialize(options = {})
  options = {
    :debug    => false,
    :domain   => nil,
    :key      => nil,
    :config   => File.join(DEFAULT_PATH, DEFAULT_FILE),
    :path     => nil,
    :protocol => "http"
  }.merge(options)

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

  @config = {
    :key      => options[:key] || config[:key],
    :domain   => options[:domain] || config[:domain],
    :protocol => options[:protocol] || config[:protocol],
    :path     => DEFAULT_PATH  || config[:path]
  }
  update if @config != config
end

Instance Method Details

#domainObject



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

def domain
  @config[:domain]
end

#keyObject



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

def key
  @config[:key]
end

#locationObject



56
57
58
# File 'lib/redmine/config.rb', line 56

def location
  @config_path
end

#pathObject

Path where to store data



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

def path
  @config[:path]
end

#protocolObject



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

def protocol
  @config[:protocol]
end

#to_hashObject



65
66
67
68
69
70
71
72
# File 'lib/redmine/config.rb', line 65

def to_hash
  {
    :debug    => debug?,
    :key      => key,
    :domain   => domain,
    :protocol => protocol
  }
end

#updateObject

Write current config to disc



61
62
63
# File 'lib/redmine/config.rb', line 61

def update
  update_config(@config, @config_path)
end