Class: LaunchdTools::LaunchdJob
- Inherits:
-
Object
- Object
- LaunchdTools::LaunchdJob
- Defined in:
- lib/launchd_tools/launchd_job.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #environment_variables ⇒ Object
-
#initialize(attributes = {}) ⇒ LaunchdJob
constructor
A new instance of LaunchdJob.
- #program_arguments ⇒ Object
-
#shellescape(str) ⇒ Object
from ruby’s shellescape included here for ruby 1.8 compatibility.
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ LaunchdJob
Returns a new instance of LaunchdJob.
4 5 6 |
# File 'lib/launchd_tools/launchd_job.rb', line 4 def initialize(attributes = {}) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/launchd_tools/launchd_job.rb', line 3 def attributes @attributes end |
Instance Method Details
#environment_variables ⇒ Object
8 9 10 |
# File 'lib/launchd_tools/launchd_job.rb', line 8 def environment_variables attributes.fetch('EnvironmentVariables', {}) end |
#program_arguments ⇒ Object
12 13 14 |
# File 'lib/launchd_tools/launchd_job.rb', line 12 def program_arguments attributes.fetch('ProgramArguments', []) end |
#shellescape(str) ⇒ Object
from ruby’s shellescape included here for ruby 1.8 compatibility
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/launchd_tools/launchd_job.rb', line 23 def shellescape(str) str = str.to_s # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? str = str.dup # Treat multibyte characters as is. It is caller's responsibility # to encode the string in the right encoding for the shell # environment. str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1") # A LF cannot be escaped with a backslash because a backslash + LF # combo is regarded as line continuation and simply ignored. str.gsub!(/\n/, "'\n'") return str end |
#to_s ⇒ Object
16 17 18 19 |
# File 'lib/launchd_tools/launchd_job.rb', line 16 def to_s escaped_args = program_arguments.map {|arg| shellescape(arg) } puts (environment_variables + escaped_args).join(" ") end |