Class: Gitlab::Graphql::Loaders::LazyRelationLoader::RelationProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/graphql/loaders/lazy_relation_loader/relation_proxy.rb

Overview

Proxies all the method calls to Registry instance. The main purpose of having this is that calling load on an instance of this class will only return the records associated with the main Active Record model.

Instance Method Summary collapse

Constructor Details

#initialize(object, registry) ⇒ RelationProxy

Returns a new instance of RelationProxy.



12
13
14
15
# File 'lib/gitlab/graphql/loaders/lazy_relation_loader/relation_proxy.rb', line 12

def initialize(object, registry)
  @object = object
  @registry = registry
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object (private)

Delegate everything to registry



37
38
39
40
41
42
43
# File 'lib/gitlab/graphql/loaders/lazy_relation_loader/relation_proxy.rb', line 37

def method_missing(method_name, ...)
  result = registry.public_send(method_name, ...) # rubocop:disable GitlabSecurity/PublicSend

  return self if result == registry

  result
end

Instance Method Details

#last(limit = 1) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/graphql/loaders/lazy_relation_loader/relation_proxy.rb', line 22

def last(limit = 1)
  result = registry.limit(limit)
                 .reverse_order!
                 .for(object)

  return result.first if limit == 1 # This is the Active Record behavior

  result
end

#loadObject Also known as: to_a



17
18
19
# File 'lib/gitlab/graphql/loaders/lazy_relation_loader/relation_proxy.rb', line 17

def load
  registry.for(object)
end