class Profile
this is me learning how to write ruby gems no idea why, but if I don't put the Profile
class in this file things break in spectacular ways
Attributes
homebrew[R]
name[R]
shell[R]
Public Class Methods
new(profile_name = 'default')
click to toggle source
# File lib/bashman.rb, line 79 def initialize(profile_name = 'default') @name = profile_name end
Public Instance Methods
add_homebrew(verbose = false)
click to toggle source
# File lib/bashman.rb, line 83 def add_homebrew(verbose = false) @homebrew = Profile::HomeBrew.new puts "Looking for Homebrew" if verbose if @homebrew.installed? puts "Homebrew executable found" if verbose puts "Getting installed homebrew packages and casks" @homebrew.get_installed if verbose puts "Found formulae:" @homebrew.formulae.each {|f| puts " #{f}"} puts "Found casks:" @homebrew.casks.each {|c| puts " #{c}"} end else puts "Homebrew executable not found" end end
add_shell(verbose = false)
click to toggle source
# File lib/bashman.rb, line 101 def add_shell(verbose = false) @shell = Profile::Shell.new puts "Gathering shell components" if verbose puts "Found shell #{@shell.shell}" if verbose puts "Getting files to save" if verbose @shell.get_dotfiles if verbose puts "Found shell files to save:" @shell.dotfiles.each {|d| puts " #{d}"} end end
save(dir = '~/.bashman/profiles', profile_name = 'default', overwrite = false, verbose = false)
click to toggle source
# File lib/bashman.rb, line 113 def save(dir = '~/.bashman/profiles', profile_name = 'default', overwrite = false, verbose = false) dir = File.expand_path(dir) FileUtils.mkdir_p(dir) if not Dir.exists?(dir) # get the current unix timestamp for later use when # creating new saved profiles @timestamp = Time.now.to_i # get timestamp from manifest in the event we need to back up files manifest = "#{dir}/#{profile_name}.json" puts "Saving manifest file #{manifest}" if verbose timestamp = nil if not overwrite if File.exists?(manifest) begin timestamp = JSON.parse(File.read(manifest))['@timestamp'] rescue timestamp = File.mtime(manifest).to_i if timestamp.nil? end FileUtils.mv(manifest, "#{manifest}.#{timestamp}") end end # now save shell files and write manifest if instance_variable_defined?("@shell") shell = @shell.to_hash @shell.save_dotfiles("#{dir}/#{profile_name}.tar.gz", timestamp, overwrite) @shell = shell end if instance_variable_defined?("@homebrew") homebrew = @homebrew.to_hash @homebrew = homebrew end manifest_content = self.to_json File.open(manifest, 'w') do |file| file.write(manifest_content) end end