Module: LaunchDr::Task

Defined in:
lib/launchdr/task.rb

Class Method Summary collapse

Class Method Details

.new(name = :launchd, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/launchdr/task.rb', line 6

def self.new name = :launchd, opts = {}
  raise "`LaunchDr.task`'s options must include the name of the binary for your gem!" unless opts[:bin]
  opts = {:desc => 'Creates a launchd property list for this gem', :arguments => []}.merge opts

  desc opts[:desc] unless opts[:no_desc]
  task name do
    LaunchDr "rb.launchdr.#{opts[:bin]}" do |plist|
      plist[:program_arguments] = [File.join('/usr/local/bin', opts[:bin]), opts[:arguments]].flatten
      plist[:keep_alive] = true
      plist[:run_at_load] = true
    end
    puts "** `#{[opts[:bin], opts[:arguments]].flatten.join(' ')}` will now be run on startup!"
  end

end