Class: LockJar::Config

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

Overview

Global configuration for LockJar

Constant Summary collapse

CONFIG_ENV =
'LOCKJAR_CONFIG'.freeze
DEFAULT_FILENAME =
'.lockjar'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

{

'repositories' => {
  ':url' => {
    'username' => ''
    'password' => ''
  }
}

}



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

def initialize(config)
  @repositories = config['repositories'] || {}
end

Instance Attribute Details

#repositoriesObject (readonly)

Returns the value of attribute repositories.



9
10
11
# File 'lib/lock_jar/config.rb', line 9

def repositories
  @repositories
end

Class Method Details

.load_config_fileObject

Load .lockjar YAML config file from ENV, current_dir, or home dir.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lock_jar/config.rb', line 14

def load_config_file
  local_config_paths =
    [Dir.pwd, Dir.home]
    .map { |path| File.join(path, DEFAULT_FILENAME) }

  config_path =
    ([ENV[CONFIG_ENV]] + local_config_paths)
    .compact
    .find { |path| File.exist? path }

  new(YAML.load_file(config_path)) if config_path
end