Class: Gemstash::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gemstash/configuration.rb

Overview

:nodoc:

Defined Under Namespace

Classes: MissingFileError

Constant Summary collapse

DEFAULTS =
{
  cache_type: "memory",
  base_path: File.expand_path("~/.gemstash"),
  db_adapter: "sqlite3",
  bind: "tcp://0.0.0.0:9292",
  rubygems_url: "https://rubygems.org"
}.freeze
DEFAULT_FILE =
File.expand_path("~/.gemstash/config.yml").freeze

Instance Method Summary collapse

Constructor Details

#initialize(file: nil, config: nil) ⇒ Configuration

Returns a new instance of Configuration.

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gemstash/configuration.rb', line 24

def initialize(file: nil, config: nil)
  if config
    @config = DEFAULTS.merge(config).freeze
    return
  end

  raise MissingFileError, file if file && !File.exist?(file)
  file ||= DEFAULT_FILE

  if File.exist?(file)
    @config = YAML.load_file(file)
    @config = DEFAULTS.merge(@config)
    @config.freeze
  else
    @config = DEFAULTS
  end
end

Instance Method Details

#[](key) ⇒ Object



46
47
48
# File 'lib/gemstash/configuration.rb', line 46

def [](key)
  @config[key]
end

#default?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/gemstash/configuration.rb', line 42

def default?(key)
  @config[key] == DEFAULTS[key]
end