Class: RestPack::Serializer::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/restpack_serializer/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



5
6
7
8
9
# File 'lib/restpack_serializer/result.rb', line 5

def initialize
  @resources = {}
  @meta = {}
  @links = {}
end

Instance Attribute Details

Returns the value of attribute links.



3
4
5
# File 'lib/restpack_serializer/result.rb', line 3

def links
  @links
end

#metaObject

Returns the value of attribute meta.



3
4
5
# File 'lib/restpack_serializer/result.rb', line 3

def meta
  @meta
end

#resourcesObject

Returns the value of attribute resources.



3
4
5
# File 'lib/restpack_serializer/result.rb', line 3

def resources
  @resources
end

Instance Method Details

#serializeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/restpack_serializer/result.rb', line 11

def serialize
  result = {}

  unless @resources.empty?
    inject_has_many_links!
    result[@resources.keys.first] = @resources.values.first

    linked = @resources.except(@resources.keys.first)
    result[:linked] = linked unless linked.empty?
  end

  result[:links] = @links unless @links.empty?
  result[:meta] = @meta unless @meta.empty?

  result
end