Class: Bicho::Plugins::User

Inherits:
Object
  • Object
show all
Defined in:
lib/bicho/plugins/user.rb

Overview

Plugin to get preferences from the user home directory .config/bicho/config.yml

Constant Summary collapse

DEFAULT_CONFIG_PATH =
File.join(ENV['HOME'], '.config', 'bicho', 'config.yml')

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUser



21
22
23
24
# File 'lib/bicho/plugins/user.rb', line 21

def initialize
  @config = {}
  @config = YAML.load_file(Bicho::Plugins::User.config_path) if File.exist?(Bicho::Plugins::User.config_path)
end

Class Attribute Details

.config_pathObject



17
18
19
# File 'lib/bicho/plugins/user.rb', line 17

def self.config_path
  @config_path ||= DEFAULT_CONFIG_PATH
end

Instance Method Details

#default_site_url_hook(logger) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/bicho/plugins/user.rb', line 26

def default_site_url_hook(logger)
  if @config.key?('default')
    ret = @config['default']
    logger.debug "Default url set to '#{ret}'"
    ret
  else
    logger.warn 'Use .config/bicho/config.yaml to setup a default bugzilla site'
  end
end

#transform_site_url_hook(url, logger) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/bicho/plugins/user.rb', line 36

def transform_site_url_hook(url, logger)
  if @config['aliases']&.key?(url.to_s)
    ret = @config['aliases'][url.to_s]
    logger.debug "Transformed '#{url}' to '#{ret}'"
    ret
  else
    url
  end
end