Module: Crm::Core::Mixins::Modifiable

Extended by:
ActiveSupport::Concern, ClassMethods
Included in:
Account, Activity, Crm::Collection, Crm::Contact, Event, EventContact, Mailing, Type
Defined in:
lib/crm/core/mixins/modifiable.rb

Overview

Modifiable is a collection of methods that are used to .create, #update, #delete, and #undelete an Infopark WebCRM item.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from ClassMethods

create

Instance Method Details

#deleteself Also known as: destroy

Soft-deletes this item (i.e. marks it as deleted).

The deleted item can be undeleted.

Examples:

contact.deleted?
# => false

contact.delete
# => Crm::Contact

contact.deleted?
# => true

Raises:



73
74
75
# File 'lib/crm/core/mixins/modifiable.rb', line 73

def delete
  load_attributes(RestApi.instance.delete(path, nil, if_match_header))
end

#deleted?Boolean

Returns true if the item was deleted (i.e. item.deleted_at is not empty).



96
97
98
# File 'lib/crm/core/mixins/modifiable.rb', line 96

def deleted?
  self['deleted_at'].present?
end

#undeleteself

Undeletes this deleted item.

Examples:

contact.deleted?
# => true

contact.undelete
# => Crm::Contact

contact.deleted?
# => false


89
90
91
# File 'lib/crm/core/mixins/modifiable.rb', line 89

def undelete
  load_attributes(RestApi.instance.put("#{path}/undelete", {}))
end

#update(attributes = {}) ⇒ self

Updates the attributes of this item.

Examples:

contact.last_name
# => 'Smith'

contact.locality
# => 'New York'

contact.update({locality: 'Boston'})
# => Crm::Contact

contact.last_name
# => 'Smith'

contact.locality
# => 'Boston'

Raises:



53
54
55
# File 'lib/crm/core/mixins/modifiable.rb', line 53

def update(attributes = {})
  load_attributes(RestApi.instance.put(path, attributes, if_match_header))
end