Class: GraphQL::Define::DefinedObjectProxy
- Inherits:
- 
      Object
      
        - Object
- GraphQL::Define::DefinedObjectProxy
 
- Extended by:
- Ruby2Keywords
- Defined in:
- lib/graphql/define/defined_object_proxy.rb
Overview
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.
Instance Attribute Summary collapse
- 
  
    
      #target  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The object which will be defined by definition functions. 
Instance Method Summary collapse
- 
  
    
      #initialize(target)  ⇒ DefinedObjectProxy 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of DefinedObjectProxy. 
- 
  
    
      #method_missing(name, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Lookup a function from the dictionary and call it if it’s found. 
- 
  
    
      #respond_to_missing?(name, include_private = false)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #types  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Provides shorthand access to GraphQL’s built-in types. 
- 
  
    
      #use(plugin, **kwargs)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Allow pluginto perform complex initialization on the definition.
Methods included from Ruby2Keywords
Constructor Details
#initialize(target) ⇒ DefinedObjectProxy
Returns a new instance of DefinedObjectProxy.
| 13 14 15 16 | # File 'lib/graphql/define/defined_object_proxy.rb', line 13 def initialize(target) @target = target @dictionary = target.class.dictionary end | 
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Lookup a function from the dictionary and call it if it’s found.
| 37 38 39 40 41 42 43 44 45 | # File 'lib/graphql/define/defined_object_proxy.rb', line 37 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 | 
Instance Attribute Details
#target ⇒ Object (readonly)
The object which will be defined by definition functions
| 11 12 13 | # File 'lib/graphql/define/defined_object_proxy.rb', line 11 def target @target end | 
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
| 48 49 50 | # File 'lib/graphql/define/defined_object_proxy.rb', line 48 def respond_to_missing?(name, include_private = false) @dictionary[name] || super end | 
#types ⇒ Object
Provides shorthand access to GraphQL’s built-in types
| 19 20 21 | # File 'lib/graphql/define/defined_object_proxy.rb', line 19 def types GraphQL::Define::TypeDefiner.instance end | 
#use(plugin, **kwargs) ⇒ Object
Allow plugin to perform complex initialization on the definition.
Calls plugin.use(defn, **kwargs).
| 27 28 29 30 31 32 33 34 | # File 'lib/graphql/define/defined_object_proxy.rb', line 27 def use(plugin, **kwargs) # https://bugs.ruby-lang.org/issues/10708 if kwargs == {} plugin.use(self) else plugin.use(self, **kwargs) end end |