Class: Graphiti::Util::SerializerRelationship

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class, serializer, sideload) ⇒ SerializerRelationship

Returns a new instance of SerializerRelationship.



34
35
36
37
38
# File 'lib/graphiti/util/serializer_relationships.rb', line 34

def initialize(resource_class, serializer, sideload)
  @resource_class = resource_class
  @serializer = serializer
  @sideload = sideload
end

Class Method Details

If we can't eagerly validate links on app boot, we do it at runtime To avoid any performance confusion, this caches that lookup



51
52
53
# File 'lib/graphiti/util/serializer_relationships.rb', line 51

def self.validated_link_cache
  @validated_link_cache ||= []
end

Instance Method Details

#applyObject



40
41
42
43
44
45
46
47
# File 'lib/graphiti/util/serializer_relationships.rb', line 40

def apply
  sideload = @sideload
  # Reassign rather than mutate: ancestors share the hash by reference
  # until a subclass writes to it.
  @serializer.relationship_sideloads =
    @serializer.relationship_sideloads.merge(@sideload.name => @sideload)
  @serializer.relationship(@sideload.name, if: -> { sideload.readable? }, &block)
end