Class: Flatpack::Core::Packer

Inherits:
Object
  • Object
show all
Includes:
MapInitialize
Defined in:
lib/flatpack/core/packer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MapInitialize

#initialize, #set_properties

Instance Attribute Details

#prettyObject

Returns the value of attribute pretty.



10
11
12
# File 'lib/flatpack/core/packer.rb', line 10

def pretty
  @pretty
end

#verboseObject

Returns the value of attribute verbose.



10
11
12
# File 'lib/flatpack/core/packer.rb', line 10

def verbose
  @verbose
end

Instance Method Details

#pack(entity) ⇒ Object

Generate a FlatPack JSON string from the given entity



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flatpack/core/packer.rb', line 13

def pack(entity)
  return {} unless entity

  @uuid_stack = []
  @all_entities = {}
  @data = {}

  recursive_pack(entity)

  json = {
      :data => @data,
      :value => entity.uuid
  }
  json = @pretty ? JSON.pretty_generate(json) : json.to_json

  if(@verbose)
    puts "*** Serializing #{entity.entity_name} to FlatPack ***"
    puts json
  end

  json
end