Module: Rails::GraphQL::Helpers::WithNamespace

Included in:
Alternative::FieldSet, Alternative::Query, Source
Defined in:
lib/rails/graphql/helpers/with_namespace.rb

Overview

Helper module that allows other objects to hold namespaces. It can either work as an extension of the superclass using add_namespace or it can be reset then set using namespace.

Instance Method Summary collapse

Instance Method Details

#namespace(*list) ⇒ Object

Add more namespaces to the list already defined. If the super class has already defined namespaces, the extend that list.



28
29
30
31
32
33
# File 'lib/rails/graphql/helpers/with_namespace.rb', line 28

def namespace(*list)
  @namespaces = (superclass.try(:namespaces)&.dup || Set.new) \
    unless defined?(@namespaces)

  @namespaces.merge(normalize_namespaces(list))
end

#namespacesObject

Returns the list of defined namespaces



11
12
13
14
15
16
17
# File 'lib/rails/graphql/helpers/with_namespace.rb', line 11

def namespaces
  return @namespaces if defined?(@namespaces)
  superclass.try(:namespaces) || begin
    value = GraphQL.type_map.associated_namespace_of(self)
    @namespaces = value unless value.nil?
  end
end

#set_namespace(*list) ⇒ Object Also known as: set_namespaces

Set or overwrite the list of namespaces



20
21
22
# File 'lib/rails/graphql/helpers/with_namespace.rb', line 20

def set_namespace(*list)
  @namespaces = normalize_namespaces(list).to_set
end