Module: CapsuleCRM::Serializable

Extended by:
ActiveSupport::Concern
Included in:
Address, Case, Country, Currency, CustomField, CustomFieldDefinition, Email, History, Milestone, Opportunity, Organization, Party, Person, Phone, Task, TaskCategory, Track, User, Website
Defined in:
lib/capsule_crm/serializable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

We need to use “self.included” here instead of “included do” to make sure that organizations and people don’t inherit a pointer to the serializable_options of their parent class and modify that.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/capsule_crm/serializable.rb', line 8

def self.included(base)
  base.send :class_attribute, :serializable_options

  base.serializable_options = OpenStruct.new(
    collection_root: base.to_s.demodulize.downcase.pluralize,
    root: base.to_s.demodulize.downcase.singularize,
    include_root: true,
    excluded_keys: [],
    additional_methods: []
  )
end

Instance Method Details

#serializerObject



24
25
26
# File 'lib/capsule_crm/serializable.rb', line 24

def serializer
  @serializer ||= CapsuleCRM::Serializer.new(self.serializable_options)
end

#to_capsule_jsonObject



20
21
22
# File 'lib/capsule_crm/serializable.rb', line 20

def to_capsule_json
  serializer.serialize(self)
end