Class: MergetrainCheck::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(file = DEFAULT_CONFIG_FILE) ⇒ Config

Returns a new instance of Config.



72
73
74
75
76
77
78
79
80
# File 'lib/mergetrain_check/config.rb', line 72

def initialize(file = DEFAULT_CONFIG_FILE)
  if File.exist?(file)
    @config = YAML.load(File.read(file))
    @config = {} if @config.nil?
  else
    @config = {}
  end
  @tokenStorage = AuthTokenStorage.new(gitlab_host)
end

Instance Method Details

#auth_tokenObject



50
51
52
# File 'lib/mergetrain_check/config.rb', line 50

def auth_token
  @tokenStorage.password
end

#auth_token=(value) ⇒ Object



54
55
56
# File 'lib/mergetrain_check/config.rb', line 54

def auth_token=(value)
  @tokenStorage.password = value
end

#gitlab_hostObject



33
34
35
# File 'lib/mergetrain_check/config.rb', line 33

def gitlab_host
  @config[:host] || "www.gitlab.com"
end

#gitlab_host=(value) ⇒ Object



45
46
47
48
# File 'lib/mergetrain_check/config.rb', line 45

def gitlab_host=(value)
  @config[:host] = value
  @tokenStorage = AuthTokenStorage.new(value)
end

#merge!(config_hash) ⇒ Object



66
67
68
69
70
# File 'lib/mergetrain_check/config.rb', line 66

def merge!(config_hash)
  @config.merge! config_hash.reject { |k,v| k == :token }
  @tokenStorage = AuthTokenStorage.new(gitlab_host)
  @tokenStorage.password = config_hash[:token] unless config_hash[:token].nil?
end

#project_idObject



58
59
60
# File 'lib/mergetrain_check/config.rb', line 58

def project_id
  @config[:project_id]
end

#project_id=(value) ⇒ Object



62
63
64
# File 'lib/mergetrain_check/config.rb', line 62

def project_id=(value)
  @config[:project_id] = value
end

#save!(file = DEFAULT_CONFIG_FILE) ⇒ Object



82
83
84
85
# File 'lib/mergetrain_check/config.rb', line 82

def save!(file = DEFAULT_CONFIG_FILE)
        File.open(file, 'w') { |f| f.write(config_to_persist.to_yaml) }
  @tokenStorage.save!
end

#verboseObject



37
38
39
# File 'lib/mergetrain_check/config.rb', line 37

def verbose
  @config[:verbose]
end

#verbose=(value) ⇒ Object



41
42
43
# File 'lib/mergetrain_check/config.rb', line 41

def verbose=(value)
  @confing[:verbose] = value
end