Class: Graphiti::Util::SerializerAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/util/serializer_attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, attr, resource, serializer, extra) ⇒ SerializerAttribute

Returns a new instance of SerializerAttribute.



4
5
6
7
8
9
10
# File 'lib/graphiti/util/serializer_attributes.rb', line 4

def initialize(name, attr, resource, serializer, extra)
  @name = name
  @attr = attr
  @resource = resource
  @serializer = serializer
  @extra = extra
end

Instance Method Details

#applyObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/graphiti/util/serializer_attributes.rb', line 12

def apply
  return unless readable?

  remove_guard if previously_guarded?

  if @name == :id
    @serializer.id(&proc)
  elsif @attr[:proc] ||
      !previously_applied? ||
      previously_applied_via_resource?
    @serializer.send(_method, @name, serializer_options, &proc)
  else # Previously applied via explicit serializer, so wrap it
    inner = @serializer.attribute_blocks.delete(@name)
    wrapped = wrap_proc(inner)
    @serializer.send(_method, @name, serializer_options, &wrapped)
  end

  existing = @serializer.send(applied_method)
  @serializer.send(:"#{applied_method}=", [@name] | existing)

  @serializer.meta do
    if !!@resource.try(:cursor_paginatable?) && !Graphiti.context[:graphql]
      {cursor: cursor}
    end
  end
end