Class: MergetrainCheck::Config
- Inherits:
-
Object
- Object
- MergetrainCheck::Config
- Defined in:
- lib/mergetrain_check/config.rb
Instance Method Summary collapse
- #auth_token ⇒ Object
- #auth_token=(value) ⇒ Object
- #gitlab_host ⇒ Object
- #gitlab_host=(value) ⇒ Object
-
#initialize(file = DEFAULT_CONFIG_FILE) ⇒ Config
constructor
A new instance of Config.
- #merge!(config_hash) ⇒ Object
- #project_id ⇒ Object
- #project_id=(value) ⇒ Object
- #save!(file = DEFAULT_CONFIG_FILE) ⇒ Object
Constructor Details
#initialize(file = DEFAULT_CONFIG_FILE) ⇒ Config
67 68 69 70 71 72 73 74 75 |
# File 'lib/mergetrain_check/config.rb', line 67 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_token ⇒ Object
45 46 47 |
# File 'lib/mergetrain_check/config.rb', line 45 def auth_token @tokenStorage.password end |
#auth_token=(value) ⇒ Object
49 50 51 |
# File 'lib/mergetrain_check/config.rb', line 49 def auth_token=(value) @tokenStorage.password = value end |
#gitlab_host ⇒ Object
36 37 38 |
# File 'lib/mergetrain_check/config.rb', line 36 def gitlab_host @config[:host] || "www.gitlab.com" end |
#gitlab_host=(value) ⇒ Object
40 41 42 43 |
# File 'lib/mergetrain_check/config.rb', line 40 def gitlab_host=(value) @config[:host] = value @tokenStorage = AuthTokenStorage.new(value) end |
#merge!(config_hash) ⇒ Object
61 62 63 64 65 |
# File 'lib/mergetrain_check/config.rb', line 61 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_id ⇒ Object
53 54 55 |
# File 'lib/mergetrain_check/config.rb', line 53 def project_id @config[:project_id] end |
#project_id=(value) ⇒ Object
57 58 59 |
# File 'lib/mergetrain_check/config.rb', line 57 def project_id=(value) @config[:project_id] = value end |
#save!(file = DEFAULT_CONFIG_FILE) ⇒ Object
77 78 79 80 |
# File 'lib/mergetrain_check/config.rb', line 77 def save!(file = DEFAULT_CONFIG_FILE) File.open(file, 'w') { |f| f.write(@config.to_yaml) } @tokenStorage.save! end |