Class: Repofetch::Config
- Inherits:
-
Object
- Object
- Repofetch::Config
- Defined in:
- lib/repofetch/config.rb
Overview
Utilities for managing config.
Constant Summary collapse
- DEFAULT_CONFIG =
File.read(File.('DEFAULT_CONFIG', __dir__))
Class Method Summary collapse
-
.load ⇒ Object
Loads from config file.
-
.load! ⇒ Object
Loads from a config file if it exists.
-
.path ⇒ Object
The path to the config file.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #emojis=(emojis) ⇒ Object
-
#emojis? ⇒ Boolean
Should emojis be shown.
-
#initialize(config_yaml = '') ⇒ Config
constructor
A new instance of Config.
- #plugins ⇒ Object
Constructor Details
#initialize(config_yaml = '') ⇒ Config
Returns a new instance of Config.
32 33 34 |
# File 'lib/repofetch/config.rb', line 32 def initialize(config_yaml = '') @config = YAML.safe_load(config_yaml, symbolize_names: true) || {} end |
Class Method Details
.load ⇒ Object
Loads from config file.
11 12 13 |
# File 'lib/repofetch/config.rb', line 11 def self.load new(File.read(path)) end |
.load! ⇒ Object
Loads from a config file if it exists. If it doesn't, it writes the config file, then creates a default.
22 23 24 25 26 27 28 29 |
# File 'lib/repofetch/config.rb', line 22 def self.load! if File.exist?(path) self.load else File.write(path, DEFAULT_CONFIG) new(DEFAULT_CONFIG) end end |
.path ⇒ Object
The path to the config file.
16 17 18 |
# File 'lib/repofetch/config.rb', line 16 def self.path File.('.repofetch.yml', Dir.home) end |
Instance Method Details
#[](key) ⇒ Object
49 50 51 |
# File 'lib/repofetch/config.rb', line 49 def [](key) @config[key] end |
#emojis=(emojis) ⇒ Object
45 46 47 |
# File 'lib/repofetch/config.rb', line 45 def emojis=(emojis) @config[:emojis] = emojis end |
#emojis? ⇒ Boolean
Should emojis be shown
41 42 43 |
# File 'lib/repofetch/config.rb', line 41 def emojis? @config[:emojis].nil? || @config[:emojis] end |
#plugins ⇒ Object
36 37 38 |
# File 'lib/repofetch/config.rb', line 36 def plugins @config[:plugins] || [] end |