Class: BackupRepos::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = BackupRepos::Mash.new({})) ⇒ Config

Returns a new instance of Config.



10
11
12
# File 'lib/backup_repos/config.rb', line 10

def initialize(options = BackupRepos::Mash.new({}))
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object



39
40
41
42
43
# File 'lib/backup_repos/config.rb', line 39

def method_missing(name, *_args)
  return options.send(name) if options.respond_to?(name)

  config[name.to_s]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/backup_repos/config.rb', line 8

def options
  @options
end

Instance Method Details

#backup_rootObject



20
21
22
23
24
# File 'lib/backup_repos/config.rb', line 20

def backup_root
  return if backup_root_dir.blank?

  File.expand_path(backup_root_dir)
end

#config_fileObject



49
50
51
52
53
# File 'lib/backup_repos/config.rb', line 49

def config_file
  return File.join(Dir.home, '.backup-repos') if options.config_path.blank?

  File.expand_path(options.config_path)
end

#debugObject

OPTIONS



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

def debug
  options.debug || config['debug']
end

#dig(*args) ⇒ Object



55
56
57
# File 'lib/backup_repos/config.rb', line 55

def dig(*args)
  config.dig(*args)
end

#github_access_tokenObject



26
27
28
29
# File 'lib/backup_repos/config.rb', line 26

def github_access_token
  config_token = config['github']['access_token'] if config['github']
  options.github_access_token || config_token
end

#only_listObject



31
32
33
34
35
# File 'lib/backup_repos/config.rb', line 31

def only_list
  return if options.only.blank?

  options.only.split(',').map(&:strip)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/backup_repos/config.rb', line 45

def respond_to_missing?(name, include_private = false)
  options.respond_to?(name) || config.key?(name.to_s) || super
end