Class: Peaberry::PlistInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/peaberry/plist_installer.rb

Constant Summary collapse

PLIST_ERB_PATH =
File.join(File.dirname(__FILE__), '../../com.github.peaberry.plist.erb')
PLIST_PATH =
File.expand_path('~/Library/LaunchAgents/com.github.peaberry.plist')

Instance Method Summary collapse

Instance Method Details

#installObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/peaberry/plist_installer.rb', line 10

def install
  dir = File.dirname(PLIST_PATH)
  FileUtils.mkdir_p(dir) unless FileTest.directory?(dir)
  open(PLIST_PATH, 'w') do |plist|
    ruby_bin_path =
      if RbConfig.respond_to?(:ruby)
        RbConfig.ruby
      else
        File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
      end
    peaberry_script_path = File.expand_path(File.join(File.dirname(__FILE__), '../../bin/peaberry'))
    plist.print ERB.new(File.read(PLIST_ERB_PATH)).result(binding)
  end
  system 'launchctl', 'load', PLIST_PATH
end