Class: Geoffrey::Package
- Inherits:
-
Object
- Object
- Geoffrey::Package
- Includes:
- FileHelper, Reporter
- Defined in:
- lib/geoffrey/package.rb
Overview
This class helps installing packages and other apps into your system.
Instance Attribute Summary collapse
-
#creates ⇒ Object
Returns the value of attribute creates.
-
#description ⇒ Object
Returns the value of attribute description.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#file ⇒ Object
Returns the value of attribute file.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format ⇒ Object
Returns the value of attribute format.
-
#guessed_name ⇒ Object
Returns the value of attribute guessed_name.
-
#options(val = nil) ⇒ Object
We will do some kind of symbolize_keys, but manually so we don’t have to use activesupport just for this.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#download_and_decompress ⇒ Object
Uses the url provided to download the file.
-
#file_to_install ⇒ Object
If it was specified through options, then get that, otherwise get the first file with .pkg extension.
- #fits?(pattern) ⇒ Boolean
-
#get_name ⇒ Object
Dumb method to get its already defined name, to avoid some precocious naming.
-
#initialize ⇒ Package
constructor
A new instance of Package.
-
#install ⇒ Object
Does the actual installing of the package For .pkg files it executes installer.
- #name(val = nil) ⇒ Object
-
#process ⇒ Object
The idea is to put together everything that has to be done after you’ve initialized the proper attributes.
Methods included from FileHelper
#extract_filename, #remove_extension
Methods included from Reporter
#debug, #echo, #logger, #verbose
Constructor Details
#initialize ⇒ Package
Returns a new instance of Package.
29 30 31 |
# File 'lib/geoffrey/package.rb', line 29 def initialize @options = {} end |
Instance Attribute Details
#creates ⇒ Object
Returns the value of attribute creates.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def creates @creates end |
#description ⇒ Object
Returns the value of attribute description.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def description @description end |
#dir ⇒ Object
Returns the value of attribute dir.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def dir @dir end |
#file ⇒ Object
Returns the value of attribute file.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def file @file end |
#filename ⇒ Object
Returns the value of attribute filename.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def filename @filename end |
#format ⇒ Object
Returns the value of attribute format.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def format @format end |
#guessed_name ⇒ Object
Returns the value of attribute guessed_name.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def guessed_name @guessed_name end |
#options(val = nil) ⇒ Object
We will do some kind of symbolize_keys, but manually so we don’t have to use activesupport just for this. Pretty much blatantly copied from it :P.
43 44 45 |
# File 'lib/geoffrey/package.rb', line 43 def @options end |
#url ⇒ Object
Returns the value of attribute url.
26 27 28 |
# File 'lib/geoffrey/package.rb', line 26 def url @url end |
Instance Method Details
#download_and_decompress ⇒ Object
Uses the url provided to download the file. Checks the options first to see if it shouldn’t be done.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/geoffrey/package.rb', line 77 def download_and_decompress echo "URL not specified" unless @url && @url != "" get_filename and debug("filename detected: #{@filename}") return unless should_install echo @description if @description && @description != "" begin @file = Tempfile.new("geoffrey") and debug("downloading file into #{@file.path}") @file.close get_format and debug("format detected: #{@format}") @dir = "#{Dir.tmpdir}/#{filename}" and debug("will put files into temporary dir: #{@dir}") FileUtils.rm_rf dir if File.exist?(dir) FileUtils.mkdir_p dir rescue Exception => e echo "Can't find file #{@url}" debug "raised an exception #{e}" raise NotFoundError end decompress end |
#file_to_install ⇒ Object
If it was specified through options, then get that, otherwise get the first file with .pkg extension
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/geoffrey/package.rb', line 135 def file_to_install return @file_to_install if defined?(@file_to_install) @file_to_install = if @options[:file] "#{dir}/#{@options[:file]}" else candidate = Dir.glob("#{dir}/**/*.pkg").first candidate ||= Dir.glob("#{dir}/**/*.app").first candidate ||= Dir.glob("#{dir}/**/*").first candidate end end |
#fits?(pattern) ⇒ Boolean
109 110 111 |
# File 'lib/geoffrey/package.rb', line 109 def fits?(pattern) description.to_s.downcase.match(pattern) || name.to_s.downcase.match(pattern) end |
#get_name ⇒ Object
Dumb method to get its already defined name, to avoid some precocious naming
64 65 66 |
# File 'lib/geoffrey/package.rb', line 64 def get_name @name end |
#install ⇒ Object
Does the actual installing of the package For .pkg files it executes installer. For .app files it just moves it to /Applications – TODO maybe add more customization options TODO investigate other possible extensions.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/geoffrey/package.rb', line 119 def install return unless should_install case File.extname file_to_install when ".pkg" echo "Installing package" execute "installer -pkg #{file_to_install} -target /" when ".app" echo "Moving file to /Applications" FileUtils.mv file_to_install, "/Applications" end echo "Install successful" end |
#name(val = nil) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/geoffrey/package.rb', line 53 def name(val=nil) if val.nil? && @name.nil? && (!@url.nil? || !@guessed_name.nil?) @name = remove_extension(@guessed_name||get_filename) elsif !val.nil? @name = val end @name end |
#process ⇒ Object
The idea is to put together everything that has to be done after you’ve initialized the proper attributes.
70 71 72 73 |
# File 'lib/geoffrey/package.rb', line 70 def process download_and_decompress install end |