class Velcro::Setter::Base
Core logic for configuring the host system settings
Attributes
dryrun[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/velcro/setter/base.rb, line 7 def initialize(options = {}) @dryrun = options[:dryrun] || false end
setter(options = {})
click to toggle source
# File lib/velcro/setter/base.rb, line 11 def self.setter(options = {}) return Setter::Mac.new(options) if Velcro.osx? return Setter::Linux.new(options) if Velcro.linux? fail UnkownOperatingSystem, 'Velcro cannot recognize your OS' end
Public Instance Methods
apply(setting)
click to toggle source
# File lib/velcro/setter/base.rb, line 18 def apply(setting) method, args = setting, nil if setting.is_a?(Hash) method = setting.keys.first args = setting.values.first end unless respond_to?(method.to_sym, true) puts "Uknown procedure to apply setting: #{setting}" return end send(method, args) end
Private Instance Methods
apply_with_velcro(target)
click to toggle source
# File lib/velcro/setter/base.rb, line 36 def apply_with_velcro(target) send(target.to_sym) end
git(*args)
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity
# File lib/velcro/setter/base.rb, line 53 def git(*args) options = args.first || {} if options['name'] command = "git config --global user.name \"#{options['name']}\"" dryrun ? puts(command) : system(command) end if options['email'] command = "git config --global user.email \"#{options['email']}\"" dryrun ? puts(command) : system(command) end servers = [options['server'], options['servers']].flatten.compact return unless servers.any? servers.each do |server| command = "cat ~/.ssh/id_rsa.pub | ssh #{server} \"mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys\"" dryrun ? puts(command) : system(command) end end
ssh(*_args)
click to toggle source
# File lib/velcro/setter/base.rb, line 40 def ssh(*_args) if File.exist?("#{Velcro.home}/.ssh/id_rsa.pub") puts 'id_rsa.pub exists. Skipping ssh keygen' else command = 'ssh-keygen' dryrun ? puts(command) : system(command) end end