Method: Jamf::Creatable#clone
- Defined in:
- lib/jamf/api/classic/api_objects/creatable.rb
#clone(new_name, api: nil, cnx: nil) ⇒ APIObject
make a clone of this API object, with a new name. The class must be creatable
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jamf/api/classic/api_objects/creatable.rb', line 79 def clone(new_name, api: nil, cnx: nil) cnx = api if api cnx ||= @cnx raise Jamf::UnsupportedError, 'This class is not creatable in via ruby-jss' unless creatable? raise Jamf::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} already exists with that name" if \ self.class.all_names(:refresh, cnx: cnx).include? new_name orig_in_jss = @in_jss @in_jss = false orig_id = @id @id = nil orig_rsrc = @rest_rsrc @rest_rsrc = "#{self.class::RSRC_BASE}/name/#{CGI.escape new_name.to_s}" orig_cnx = @cnx @cnx = cnx new_obj = dup @in_jss = orig_in_jss @id = orig_id @rest_rsrc = orig_rsrc @cnx = orig_cnx new_obj.name = new_name new_obj end |