Class: DMG::Pkg
- Inherits:
-
Object
- Object
- DMG::Pkg
- Defined in:
- lib/dmg/pkg.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#volume_dir ⇒ Object
readonly
Returns the value of attribute volume_dir.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Pkg
constructor
A new instance of Pkg.
- #install! ⇒ Object
Constructor Details
#initialize(args) ⇒ Pkg
Returns a new instance of Pkg.
25 26 27 28 29 30 |
# File 'lib/dmg/pkg.rb', line 25 def initialize(args) @name = args['name'] @package = args['package'] @url = args['url'] @volume_dir = args['volume_dir'] || @package end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/dmg/pkg.rb', line 23 def name @name end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
23 24 25 |
# File 'lib/dmg/pkg.rb', line 23 def package @package end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
23 24 25 |
# File 'lib/dmg/pkg.rb', line 23 def url @url end |
#volume_dir ⇒ Object (readonly)
Returns the value of attribute volume_dir.
23 24 25 |
# File 'lib/dmg/pkg.rb', line 23 def volume_dir @volume_dir end |
Class Method Details
.all ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dmg/pkg.rb', line 12 def self.all return @@all if defined?(@@all) @@all = [] pkgs = YAML.load_file(File.dirname(__FILE__) + '/pkgs.yml') pkgs.each do |key, values| @@all << Pkg.new({'name' => key}.merge(values)) end @@all end |
.install(pkg_names) ⇒ Object
7 8 9 10 |
# File 'lib/dmg/pkg.rb', line 7 def self.install(pkg_names) pkgs = pkg_names.map { |pkg_name| find!(pkg_name) } pkgs.each(&:install!) end |
.list ⇒ Object
3 4 5 |
# File 'lib/dmg/pkg.rb', line 3 def self.list puts all.map(&:name) end |
Instance Method Details
#install! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dmg/pkg.rb', line 32 def install! dmg_file = "~/Downloads/#{package}.dmg" destination = '/Applications' if "hdiutil info"[/image-path.*#{dmg_file}/] puts "#{name} is already installed" return end run_cmd("curl -L #{url} -o #{dmg_file}") run_cmd("hdid #{dmg_file}") run_cmd "sudo cp -r '/Volumes/#{volume_dir}/#{package}.app' #{destination}" run_cmd "hdiutil detach '/Volumes/#{volume_dir}'" run_cmd("sudo chmod 755 #{destination}/#{package}.app/Contents/MacOS/#{package}") end |