Sha256: ee0159032fbf5ef5cf21101200ac368f08e3ab987ee964ea3687e7a450d6e404

Contents?: true

Size: 746 Bytes

Versions: 6

Compression:

Stored size: 746 Bytes

Contents

# encoding: UTF-8
require 'launchdr'
require 'fileutils'

class Boxafe::Scheduler::Launchd < Boxafe::Scheduler

  def start
    stop
    plist.dump USER_AGENT
    plist.load!
  end

  def stop
    return false unless plist_exists?
    plist.unload!
    FileUtils.rm_f plist.file
  end

  private

  LABEL = 'com.alphahydrae.boxafe'
  USER_AGENT = LaunchDr::Launchd::Paths[:user_agent]

  def plist_exists?
    begin
      File.exists? plist.file
    rescue
      false
    end
  end

  def plist
    @plist ||= LaunchDr::Launchd.new(LABEL).tap do |plist|
      plist[:ProgramArguments] = [ 'boxafe', 'mount' ]
      plist[:RunAtLoad] = true
      plist[:EnvironmentVariables] = { 'PATH' => ENV['PATH'] } # TODO: add path option
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
boxafe-0.1.5 lib/boxafe/scheduler/launchd.rb
boxafe-0.1.4 lib/boxafe/scheduler/launchd.rb
boxafe-0.1.3 lib/boxafe/scheduler/launchd.rb
boxafe-0.1.2 lib/boxafe/scheduler/launchd.rb
boxafe-0.1.1 lib/boxafe/scheduler/launchd.rb
boxafe-0.1.0 lib/boxafe/scheduler/launchd.rb