Class: Gemstash::Configuration
- Inherits:
-
Object
- Object
- Gemstash::Configuration
- Defined in:
- lib/gemstash/configuration.rb
Overview
:nodoc:
Defined Under Namespace
Classes: MissingFileError
Constant Summary collapse
- DEFAULTS =
{ cache_type: "memory", base_path: File.("~/.gemstash"), db_adapter: "sqlite3", bind: "tcp://0.0.0.0:9292", rubygems_url: "https://rubygems.org" }.freeze
- DEFAULT_FILE =
File.("~/.gemstash/config.yml").freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
- #default?(key) ⇒ Boolean
-
#initialize(file: nil, config: nil) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(file: nil, config: nil) ⇒ Configuration
Returns a new instance of Configuration.
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
42 43 44 |
# File 'lib/gemstash/configuration.rb', line 42 def default?(key) @config[key] == DEFAULTS[key] end |