Class: Crm::Type

Overview

A JustRelate WebCRM type defines a set of attributes associated with every instance of the type.

Examples:

Listing all attributes of a type

 = Crm::Type.find('account')
# => Crm::Type

# Listing all standard attributes
.standard_attribute_definitions.keys
# => ['name', 'created_at', 'updated_at', ...]

# Listing all custom attributes
.attribute_definitions.keys
# => ['custom_plan', ...]

Inspecting an attribute definition of a type

.standard_attribute_definitions["name"]
# => {
#  'attribute_type' => 'string',
#  'create'         => true,
#  'mandatory'      => true,
#  'read'           => true,
#  'title'          => 'Name',
#  'update'         => true,
# }

Adding a new custom attribute to a type

.attribute_definitions.keys
# => ['custom_plan']

# Add a new custom attribute named "custom_shipping_details"
attr_defs = .attribute_definitions.merge({
  custom_shipping_details: {
    attribute_type: 'text',
    title: 'Shipping Details',
  }
})
.update({
  attribute_definitions: attr_defs,
})
# => Crm::Type

.attribute_definitions.keys
# => ['custom_plan', 'custom_shipping_details']

Removing a custom attribute from a type

.attribute_definitions.keys
# => ['custom_plan', 'custom_shipping_details']

attr_defs = .attribute_definitions.except('custom_shipping_details')
.update({
  attribute_definitions: attr_defs,
})
# => Crm::Type

.attribute_definitions.keys
# => ['custom_plan']

Class Method Summary collapse

Methods included from Core::Mixins::Findable::ClassMethods

find

Methods included from Core::Mixins::Modifiable::ClassMethods

create

Methods included from Core::Mixins::Inspectable

#inspect

Methods included from Core::Mixins::ChangeLoggable

#changes

Methods included from Core::Mixins::Modifiable

#delete, #update

Methods inherited from Core::BasicResource

base_type, #eql?, #id, path, #path, #reload, resource_name, #type

Methods included from Core::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

.allArray<Type>

Returns all types.

Returns:



71
72
73
74
75
# File 'lib/crm/type.rb', line 71

def self.all
  Core::RestApi.instance.get('types').map do |item|
    new(item)
  end
end