class Velcro::Strap
The main entry point for velcro
Constants
- FLAGS
Attributes
host[R]
rcfile[R]
Public Class Methods
new(repo, options = {})
click to toggle source
# File lib/velcro/strap.rb, line 16 def initialize(repo, options = {}) establish_inclusions(FLAGS, options) if options.key?(:host) @host = options[:host] fail ArgumentError if host.nil? || host == '' end @dryrun = options[:dryrun] || false fail ArgumentError if repo.nil? && included?(:dotfiles) Velcro.config.repo_url = repo if repo end
Public Instance Methods
run()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/velcro/strap.rb, line 29 def run install_dotfiles Symlinker.new(dryrun: dryrun?).symlink! if included?(:symlinks) install_scaffold(rcfile) install_apps(rcfile['apps']) apply_settings(rcfile['settings']) if host set_hostname unless host == Velcro.host puts "\nSetting up #{host_data['name']}:" install_scaffold(host_data) install_apps(host_data['apps']) apply_settings(host_data['settings']) end end
Private Instance Methods
apply_settings(settings)
click to toggle source
# File lib/velcro/strap.rb, line 59 def apply_settings(settings) return unless included?(:settings) return if (settings ||= []).empty? puts "\nApplying settings:" settings.each{|setting| setter.apply(setting) } end
clone_dotfiles()
click to toggle source
# File lib/velcro/strap.rb, line 90 def clone_dotfiles tmpdir = Dir.mktmpdir shell("git clone -q #{Velcro.config.repo_url} #{tmpdir}") tmpdir end
host_data()
click to toggle source
# File lib/velcro/strap.rb, line 114 def host_data return @host_data if defined?(@host_data) @host_data = rcfile['hosts'].detect{|n| n['name'] == Velcro.hostname } puts "No host settings found for: #{Velcro.hostname}" if host_data.nil? @host_data end
install_apps(apps)
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/velcro/strap.rb, line 51 def install_apps(apps) return unless included?(:apps) return if (apps ||= []).empty? puts "\nInstalling apps:" apps.each{|app| installer.install(app) } end
install_dotfiles()
click to toggle source
# File lib/velcro/strap.rb, line 77 def install_dotfiles if included?(:dotfiles) tmpdir = clone_dotfiles @rcfile = load_rcfile(tmpdir) shell("mv #{tmpdir} #{Velcro.config.dotfiles}") puts "Dotfiles installed: #{Velcro.config.dotfiles}" else fail MissingDotfilesError unless Status::Dotfiles.installed? @rcfile = load_rcfile(Velcro.config.dotfiles) end end
install_scaffold(config)
click to toggle source
# File lib/velcro/strap.rb, line 67 def install_scaffold(config) return unless included?(:scaffold) scaffolder.install(config) end
installer()
click to toggle source
# File lib/velcro/strap.rb, line 102 def installer @installer ||= Installer::Base.installer(dryrun: dryrun) end
load_rcfile(dotfiles_dir)
click to toggle source
# File lib/velcro/strap.rb, line 96 def load_rcfile(dotfiles_dir) file = YAML.load_file(File.join(dotfiles_dir, '.velcrorc')) Velcro.config.apply file['config'] file end
scaffolder()
click to toggle source
# File lib/velcro/strap.rb, line 110 def scaffolder @scaffolder ||= Scaffold.new(dryrun: dryrun) end
set_hostname()
click to toggle source
# File lib/velcro/strap.rb, line 72 def set_hostname shell("sudo scutil --set LocalHostName #{host}") shell("sudo scutil --set ComputerName #{host}") end
setter()
click to toggle source
# File lib/velcro/strap.rb, line 106 def setter @setter ||= Setter::Base.setter(dryrun: dryrun) end