Class: Crm::Core::BasicResource

Inherits:
Object
  • Object
show all
Includes:
Mixins::AttributeProvider
Defined in:
lib/crm/core/basic_resource.rb

Overview

BasicResource is the base class of all JustRelate WebCRM SDK resources.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Class Method Details

.base_typeObject



7
8
9
# File 'lib/crm/core/basic_resource.rb', line 7

def self.base_type
  name.split(/::/).last
end

.pathObject



15
16
17
# File 'lib/crm/core/basic_resource.rb', line 15

def self.path
  resource_name.pluralize
end

.resource_nameObject



11
12
13
# File 'lib/crm/core/basic_resource.rb', line 11

def self.resource_name
  base_type.underscore
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


55
56
57
# File 'lib/crm/core/basic_resource.rb', line 55

def eql?(other)
  other.equal?(self) || other.instance_of?(self.class) && other.id == id
end

#idString

Returns the ID of this item.

Returns:

  • (String)


22
23
24
# File 'lib/crm/core/basic_resource.rb', line 22

def id
  self['id']
end

#pathObject



26
27
28
# File 'lib/crm/core/basic_resource.rb', line 26

def path
  [self.class.path, id].compact.join('/')
end

#reloadself

Reloads the attributes of this item from the remote web service.

Examples:

contact.locality
# => 'Bergen'

# Assume this contact has been modified concurrently.

contact.reload
# => Crm::Contact

contact.locality
# => 'Oslo'

Returns:

  • (self)

    the reloaded item.



51
52
53
# File 'lib/crm/core/basic_resource.rb', line 51

def reload
  load_attributes(RestApi.instance.get(path))
end

#typeCrm::Type

Returns the type object of this item.

Returns:



33
34
35
# File 'lib/crm/core/basic_resource.rb', line 33

def type
  ::Crm::Type.find(type_id)
end