Sha256: 9ba4a2c97cc44a35ee054d202a206e4752861682ee8754211046bb4f144623ed

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

module LaunchAgent
  class Base
    DOMAIN = 'com.buycheapviagraonlinenow'
    KEYS = [
      'Label',
      'Disabled',
      'UserName',
      'GroupName',
      'inetdCompatibility',
      'LimitLoadToHosts',
      'LimitLoadFromHosts',
      'LimitLoadToSessionType',
      'Program',
      'ProgramArguments',
      'EnableGlobbing',
      'EnableTransactions',
      'OnDemand',
      'KeepAlive',
      'RunAtLoad',
      'RootDirectory',
      'WorkingDirectory',
      'EnvironmentVariables',
      'Umask',
      'TimeOut',
      'ExitTimeOut',
      'ThrottleInterval',
      'InitGroups',
      'WatchPaths',
      'QueueDirectories',
      'StartOnMount',
      'StartInterval',
      'StartCalendarInterval',
      'StandardInPath',
      'StandardOutPath',
      'StandardErrorPath',
      'Debug',
      'WaitForDebugger',
      'SoftResourceLimits',
      'HardResourceLimits',
      'Nice',
      'AbandonProcessGroup',
      'LowPriorityIO',
      'LaunchOnlyOnce',
      'MachServices',
      'Sockets'
    ]

    def initialize(*args)
      @args = args
      @params = {}
      @user_params = {}
    end

    def load
      open(plist_filename, 'w') do |file|
        file.write(plist_content)
      end

      `launchctl load -w #{plist_filename}`
    end

    def unload
      `launchctl unload -w #{plist_filename}`

      File.unlink(plist_filename)
    end

    def loaded?
      `launchctl list | grep #{job_id}` =~ /#{job_id}/
    end

    def []=(key, value)
      if KEYS.include?(key)
        @user_params[key] = value
      end
    end

    def plist_filename
      File.expand_path('~/Library/LaunchAgents/' + job_id + '.plist')
    end

    def build_params
    end

    def plist_content
      build_params

      @params.merge(@user_params).to_plist
    end

    def job_id
      DOMAIN + '.' + @args.inject([]) do |m, arg|
        m << arg.gsub(/\W/, '_')
      end.join('__')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
launch-agent-0.4.0 lib/launch_agent/base.rb
launch-agent-0.3.0 lib/launch_agent/base.rb
launch-agent-0.2.0 lib/launch_agent/base.rb