Method: RunLoop::PlistBuddy#unshift_array

Defined in:
lib/run_loop/plist_buddy.rb

#unshift_array(key, type, value, path, opts = {}) ⇒ Object

Add value to the head of an array type.

Parameters:

  • key (String)

    The plist key

  • type (String)

    any allowed plist type

  • value (Object)

    the value to add

  • path (String)

    the plist path

  • opts (Hash) (defaults to: {})

    options for controlling execution

Options Hash (opts):

  • :verbose (Boolean) — default: false

    controls log level

Raises:

  • RuntimeError when running the command fails.

  • RuntimeError if attempt to push value onto non-array container.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/run_loop/plist_buddy.rb', line 153

def unshift_array(key, type, value, path, opts={})
  if !plist_key_exists?(key, path)
    run_command("Add :#{key} array", path, opts)
  else
    key_type = plist_read(key, path).split(" ")[0]
    if key_type != "Array"
      raise RuntimeError, %Q[
Could not push #{value} onto array:
  Expected:  key #{key} be of type Array
 Found:  had type #{key_type}

in plist:

  #{path}
]
    end
  end

  run_command("Add :#{key}:0 #{type} #{value}", path, opts)
end