Class: Profile
Overview
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
Defined Under Namespace
Constant Summary
Constants included from Bashman
Bashman::CONFIG, Bashman::CONFIG_PATH, Bashman::VERSION
Instance Attribute Summary collapse
-
#homebrew ⇒ Object
readonly
Returns the value of attribute homebrew.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Instance Method Summary collapse
- #add_homebrew(verbose = false) ⇒ Object
- #add_shell(verbose = false) ⇒ Object
-
#initialize(profile_name = 'default') ⇒ Profile
constructor
A new instance of Profile.
- #save(dir = '~/.bashman/profiles', profile_name = 'default', overwrite = false, verbose = false) ⇒ Object
Methods included from Bashman
Methods inherited from JSONable
#from_json!, #to_hash, #to_json
Constructor Details
#initialize(profile_name = 'default') ⇒ Profile
Returns a new instance of Profile.
79 80 81 |
# File 'lib/bashman.rb', line 79 def initialize(profile_name = 'default') @name = profile_name end |
Instance Attribute Details
#homebrew ⇒ Object (readonly)
Returns the value of attribute homebrew.
75 76 77 |
# File 'lib/bashman.rb', line 75 def homebrew @homebrew end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
77 78 79 |
# File 'lib/bashman.rb', line 77 def name @name end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
76 77 78 |
# File 'lib/bashman.rb', line 76 def shell @shell end |
Instance Method Details
#add_homebrew(verbose = false) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# 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) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/bashman.rb', line 113 def save(dir = '~/.bashman/profiles', profile_name = 'default', overwrite = false, verbose = false) dir = File.(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 = nil if not overwrite if File.exists?(manifest) begin = JSON.parse(File.read(manifest))['@timestamp'] rescue = File.mtime(manifest).to_i if .nil? end FileUtils.mv(manifest, "#{manifest}.#{}") 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", , 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 |