Class: Gitlab::Graphql::BatchKey

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/graphql/batch_key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, lookahead = nil, object_name: nil) ⇒ BatchKey

Returns a new instance of BatchKey.



10
11
12
13
14
# File 'lib/gitlab/graphql/batch_key.rb', line 10

def initialize(object, lookahead = nil, object_name: nil)
  @object = object
  @lookahead = lookahead
  @object_name = object_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs) ⇒ Object



32
33
34
35
36
37
# File 'lib/gitlab/graphql/batch_key.rb', line 32

def method_missing(method_name, *args, **kwargs)
  return @object if method_name.to_sym == @object_name
  return @object.public_send(method_name) if args.empty? && kwargs.empty? # rubocop: disable GitlabSecurity/PublicSend

  super
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



6
7
8
# File 'lib/gitlab/graphql/batch_key.rb', line 6

def object
  @object
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


27
28
29
# File 'lib/gitlab/graphql/batch_key.rb', line 27

def eql?(other)
  other.is_a?(self.class) && object == other.object
end

#requires?(path) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/graphql/batch_key.rb', line 16

def requires?(path)
  return false unless @lookahead
  return false unless path.present?

  field = path.pop

  path
    .reduce(@lookahead) { |q, f| q.selection(f) }
    .selects?(field)
end