Module: Rails::GraphQL::Source::Builder

Included in:
Rails::GraphQL::Source
Defined in:
lib/rails/graphql/source/builder.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **xargs, &block) ⇒ Object

Allows all sorts of building methods to be called



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails/graphql/source/builder.rb', line 31

def method_missing(method_name, *args, **xargs, &block)
  return super unless method_name.to_s.start_with?('build_')

  type = method_name.to_s[6..-1]
  type = type.singularize unless hook_names.include?(type.to_sym)
  type = type.to_sym
  return if built?(type)

  import_skips_for(type, xargs)
  build!(type, *args, **xargs, &block)
end

Instance Method Details

#build_allObject

Trigger a safe build of everything



20
21
22
# File 'lib/rails/graphql/source/builder.rb', line 20

def build_all
  build_all! unless abstract?
end

#build_all_sourcesObject

Build all from all descendant sources



15
16
17
# File 'lib/rails/graphql/source/builder.rb', line 15

def build_all_sources
  descendants.each(&:build_all)
end

#built?(part = nil) ⇒ Boolean

Check if the object was already built

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/rails/graphql/source/builder.rb', line 9

def built?(part = nil)
  defined?(@built) && @built.present? &&
    (part.nil? || @built.include?(part.to_sym))
end

#respond_to_missing?(method_name) ⇒ Boolean

Make sure to properly indicate about build methods

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/rails/graphql/source/builder.rb', line 25

def respond_to_missing?(method_name, *)
  return super unless method_name.to_s.start_with?('build_') &&
    hook_names.include?(method_name.to_s[6..-1].to_sym)
end