class GraphQL::Define::DefinedObjectProxy
This object delegates most methods to a dictionary of functions, {@dictionary}. {@target} is passed to the specified function, along with any arguments and block. This allows a method-based DSL without adding methods to the defined class.
Attributes
target[R]
The object which will be defined by definition functions
Public Class Methods
new(target)
click to toggle source
# File lib/graphql/define/defined_object_proxy.rb, line 10 def initialize(target) @target = target @dictionary = target.class.dictionary end
Public Instance Methods
method_missing(name, *args, &block)
click to toggle source
Lookup a function from the dictionary and call it if it's found.
# File lib/graphql/define/defined_object_proxy.rb, line 34 def method_missing(name, *args, &block) definition = @dictionary[name] if definition definition.call(@target, *args, &block) else msg = "#{@target.class.name} can't define '#{name}'" raise NoDefinitionError, msg, caller end end
respond_to_missing?(name, include_private = false)
click to toggle source
Calls superclass method
# File lib/graphql/define/defined_object_proxy.rb, line 44 def respond_to_missing?(name, include_private = false) @dictionary[name] || super end
types()
click to toggle source
Provides shorthand access to GraphQL's built-in types
# File lib/graphql/define/defined_object_proxy.rb, line 16 def types GraphQL::Define::TypeDefiner.instance end
use(plugin, **kwargs)
click to toggle source
Allow `plugin` to perform complex initialization on the definition. Calls `plugin.use(defn, **kwargs)`. @param plugin [<#use(defn, **kwargs)>] A plugin object @param kwargs [Hash] Any options for the plugin
# File lib/graphql/define/defined_object_proxy.rb, line 24 def use(plugin, **kwargs) # https://bugs.ruby-lang.org/issues/10708 if kwargs == {} plugin.use(self) else plugin.use(self, **kwargs) end end