Method: RunLoop::PlistBuddy#plist_set
- Defined in:
- lib/run_loop/plist_buddy.rb
#plist_set(key, type, value, file, opts = {}) ⇒ Boolean
Replaces or creates the value of key in the file.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/run_loop/plist_buddy.rb', line 55 def plist_set(key, type, value, file, opts={}) default_opts = {:verbose => false} merged = default_opts.merge(opts) if key.nil? or key.length == 0 raise(ArgumentError, "key '#{key}' must not be nil or empty") end cmd_args = {:key => key, :type => type, :value => value} if plist_key_exists?(key, file, merged) cmd = build_plist_cmd(:set, cmd_args, file) else cmd = build_plist_cmd(:add, cmd_args, file) end success, output = execute_plist_cmd(cmd, file, merged) if !success raise RuntimeError, %Q[ Encountered an error performing operation on plist: #{plist_buddy} -c "#{cmd}" #{file} => #{output} ] end success end |