class MacSetup::Configuration
Constants
- DEFAULT_KEYS
- InvalidConfigError
Public Class Methods
new(config_path)
click to toggle source
# File lib/mac_setup/configuration.rb, line 11 def initialize(config_path) @config_path = config_path load_config end
Public Instance Methods
add(type, value)
click to toggle source
# File lib/mac_setup/configuration.rb, line 25 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()
click to toggle source
# File lib/mac_setup/configuration.rb, line 76 def brews @brews ||= (@config["brews"] || []).each_with_object({}) do |item, merged| add_brews(item, merged) end end
casks()
click to toggle source
# File lib/mac_setup/configuration.rb, line 86 def casks @casks ||= Set.new(@config["casks"]) end
dotfiles_repo()
click to toggle source
# File lib/mac_setup/configuration.rb, line 56 def dotfiles_repo @config.fetch("repo") end
extra_dotfiles()
click to toggle source
# File lib/mac_setup/configuration.rb, line 60 def extra_dotfiles @config.fetch("extra_dotfiles", []) end
fonts()
click to toggle source
# File lib/mac_setup/configuration.rb, line 82 def fonts @fonts ||= Set.new(@config["fonts"]) end
git_repos()
click to toggle source
# File lib/mac_setup/configuration.rb, line 64 def git_repos @git_repos ||= @config["git_repos"] || {} end
mas()
click to toggle source
# File lib/mac_setup/configuration.rb, line 94 def mas @mas ||= @config["mas"] || {} end
plugins()
click to toggle source
# File lib/mac_setup/configuration.rb, line 44 def plugins @plugins ||= Set.new(@config["plugins"]) end
quicklook()
click to toggle source
# File lib/mac_setup/configuration.rb, line 90 def quicklook @quicklook ||= Set.new(@config["quicklook"]) end
require_value(key)
click to toggle source
# File lib/mac_setup/configuration.rb, line 16 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()
click to toggle source
# File lib/mac_setup/configuration.rb, line 68 def symlinks @symlinks ||= @config["symlinks"] || {} end
taps()
click to toggle source
# File lib/mac_setup/configuration.rb, line 72 def taps @taps ||= (@config["taps"] || []).map { |item| item.split(/\s+/) }.to_set end
validate!()
click to toggle source
# File lib/mac_setup/configuration.rb, line 48 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
Private Instance Methods
add_brews(item, existing_brews = brews)
click to toggle source
# File lib/mac_setup/configuration.rb, line 100 def add_brews(item, existing_brews = brews) existing_brews.merge!(brew_value(item)) do |key, oldval, newval| if oldval == newval oldval else raise InvalidConfigError, "#{key} is defined twice!: #{oldval}, #{newval}" end end end
allowed_keys()
click to toggle source
# File lib/mac_setup/configuration.rb, line 114 def allowed_keys @allowed_keys ||= Set.new(DEFAULT_KEYS) end
brew_value(item)
click to toggle source
# File lib/mac_setup/configuration.rb, line 110 def brew_value(item) item.is_a?(Hash) ? item : { item.to_s => {} } end
load_config()
click to toggle source
# File lib/mac_setup/configuration.rb, line 118 def load_config @config = YAML.load_file(@config_path) end