Class: MacSetup::Configuration
- Inherits:
-
Object
- Object
- MacSetup::Configuration
- Defined in:
- lib/mac_setup/configuration.rb
Constant Summary collapse
- InvalidConfigError =
Class.new(StandardError)
- DEFAULT_KEYS =
[:repo, :plugins, :git_repos, :symlinks, :taps, :brews, :fonts, :casks, :quicklook, :mas]
Instance Method Summary collapse
- #add(type, value) ⇒ Object
- #brews ⇒ Object
- #casks ⇒ Object
- #dotfiles_repo ⇒ Object
- #fonts ⇒ Object
- #git_repos ⇒ Object
-
#initialize(config_path) ⇒ Configuration
constructor
A new instance of Configuration.
- #mas ⇒ Object
- #plugins ⇒ Object
- #quicklook ⇒ Object
- #require_value(key) ⇒ Object
- #symlinks ⇒ Object
- #taps ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(config_path) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 |
# File 'lib/mac_setup/configuration.rb', line 9 def initialize(config_path) @config_path = config_path load_config end |
Instance Method Details
#add(type, value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mac_setup/configuration.rb', line 23 def add(type, value) add_method = "add_#{type}" if respond_to?(add_method, include_private: true) send(add_method, value) else collection = public_send(type) case collection when Set collection << value.to_s when Hash collection.merge!(value) do |key, oldval, newval| raise InvalidConfigError, "#{key} is defined twice!: #{oldval}, #{newval}" end end end end |
#brews ⇒ Object
70 71 72 73 74 |
# File 'lib/mac_setup/configuration.rb', line 70 def brews @brews ||= (@config["brews"] || []).each_with_object({}) do |item, merged| add_brews(item, merged) end end |
#casks ⇒ Object
80 81 82 |
# File 'lib/mac_setup/configuration.rb', line 80 def casks @casks ||= Set.new(@config["casks"]) end |
#dotfiles_repo ⇒ Object
54 55 56 |
# File 'lib/mac_setup/configuration.rb', line 54 def dotfiles_repo @config.fetch("repo") end |
#fonts ⇒ Object
76 77 78 |
# File 'lib/mac_setup/configuration.rb', line 76 def fonts @fonts ||= Set.new(@config["fonts"]) end |
#git_repos ⇒ Object
58 59 60 |
# File 'lib/mac_setup/configuration.rb', line 58 def git_repos @git_repos ||= @config["git_repos"] || {} end |
#mas ⇒ Object
88 89 90 |
# File 'lib/mac_setup/configuration.rb', line 88 def mas @mas ||= @config["mas"] || {} end |
#plugins ⇒ Object
42 43 44 |
# File 'lib/mac_setup/configuration.rb', line 42 def plugins @plugins ||= Set.new(@config["plugins"]) end |
#quicklook ⇒ Object
84 85 86 |
# File 'lib/mac_setup/configuration.rb', line 84 def quicklook @quicklook ||= Set.new(@config["quicklook"]) end |
#require_value(key) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/mac_setup/configuration.rb', line 14 def require_value(key) value = @config.fetch(key.to_s) do raise InvalidConfigError, "Missing config value for #{key}!" end define_singleton_method(key) { value } allowed_keys << key.to_sym end |
#symlinks ⇒ Object
62 63 64 |
# File 'lib/mac_setup/configuration.rb', line 62 def symlinks @symlinks ||= @config["symlinks"] || {} end |
#taps ⇒ Object
66 67 68 |
# File 'lib/mac_setup/configuration.rb', line 66 def taps @taps ||= (@config["taps"] || []).map { |item| item.split(/\s+/) }.to_set end |
#validate! ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/mac_setup/configuration.rb', line 46 def validate! extra_keys = @config.keys.map(&:to_sym) - allowed_keys.to_a return if extra_keys.none? raise InvalidConfigError, "Extra keys in config: #{extra_keys.join(', ')}" end |