Module: CodeModels::Serialization::SerializationFunctionalities

Included in:
CodeModelsAstNode
Defined in:
lib/codemodels/serialization.rb

Overview

Intended to be included

Defined Under Namespace

Classes: SerializationMemory

Instance Method Summary collapse

Instance Method Details

#to_hash(params = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/codemodels/serialization.rb', line 21

def to_hash(params={})
  serialization_memory = params.fetch(:memory,SerializationMemory.new)
  adapters      = params.fetch(:adapters,{})
  with_source_info  = params.fetch(:source_info,true)

  e_object = self
  map = { 'type' => type, 'id' => serialization_memory.id(e_object) }
  if with_source_info
    if self.respond_to?(:source) && self.source               
      map['source'] = source_info_to_hash(self.source)
    end
  end
  e_class = e_object.class.ecore
  e_class.eAllAttributes.sort_by { |a| a.name }.each do |a|    
    insert_attr_value_in_hash(map,a)
  end
  e_class.eAllReferences.sort_by { |r| r.name }.each do |r|
    id = insert_ref_value_in_hash(map,r,adapters,serialization_memory)
  end
  if adapters.has_key? type
    adapters[type].adapt(self,map)
  end
  map
end

#to_json(params = {}) ⇒ Object

Deprecated, use to_hash instead



17
18
19
# File 'lib/codemodels/serialization.rb', line 17

def to_json(params={})
  to_hash(params)
end