Class: Repofetch::Config

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

Overview

Utilities for managing config.

Constant Summary collapse

DEFAULT_CONFIG =
File.read(File.expand_path('DEFAULT_CONFIG', __dir__))

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_yaml = '') ⇒ Config

Returns a new instance of Config.

Parameters:

  • config_yaml (String) (defaults to: '')

    a YAML string



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

.loadObject

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

.pathObject

The path to the config file.



16
17
18
# File 'lib/repofetch/config.rb', line 16

def self.path
  File.expand_path('.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

Returns:

  • (Boolean)


41
42
43
# File 'lib/repofetch/config.rb', line 41

def emojis?
  @config[:emojis].nil? || @config[:emojis]
end

#pluginsObject



36
37
38
# File 'lib/repofetch/config.rb', line 36

def plugins
  @config[:plugins] || []
end