Module: GraphQL::Define::InstanceDefinable
- Included in:
- Argument, BaseType, GraphQL::Directive, EnumType::EnumValue, Field, Relay::Mutation, Schema
- Defined in:
- lib/graphql/define/instance_definable.rb
Overview
This module provides the .define { ... }
API for
BaseType, Field and others.
Calling .accepts_definitions(...)
creates:
- a keyword to the
.define
method - a helper method in the
.define { ... }
block
The .define { ... }
block will be called lazily. To be sure it has been
called, use the private method #ensure_defined
. That will call the
definition block if it hasn't been called already.
The goals are:
- Minimal overhead in consuming classes
- Independence between consuming classes
- Extendable by third-party libraries without monkey-patching or other nastiness
Defined Under Namespace
Modules: ClassMethods Classes: AssignAttribute, AssignMetadataKey, Definition
Instance Method Summary collapse
-
#define(**kwargs, &block) ⇒ void
Mutate this instance using functions from its definitions.
- #initialize_copy(other) ⇒ Object
-
#metadata ⇒ Hash<Object, Object>
metadata
can store arbitrary key-values with an object. -
#redefine(**kwargs, &block) ⇒ InstanceDefinable
Shallow-copy this object, then apply new definitions to the copy.
Instance Method Details
#define(**kwargs, &block) ⇒ void
This method returns an undefined value.
Mutate this instance using functions from its definitions.
Keywords or helpers in the block correspond to keys given to accepts_definitions
.
Note that the block is not called right away -- instead, it's deferred until one of the defined fields is needed.
116 117 118 119 120 121 122 |
# File 'lib/graphql/define/instance_definable.rb', line 116 def define(**kwargs, &block) # make sure the previous definition_proc was executed: ensure_defined stash_dependent_methods @pending_definition = Definition.new(kwargs, block) nil end |
#initialize_copy(other) ⇒ Object
134 135 136 137 |
# File 'lib/graphql/define/instance_definable.rb', line 134 def initialize_copy(other) super @metadata = other..dup end |
#metadata ⇒ Hash<Object, Object>
metadata
can store arbitrary key-values with an object.
106 107 108 |
# File 'lib/graphql/define/instance_definable.rb', line 106 def @metadata ||= {} end |
#redefine(**kwargs, &block) ⇒ InstanceDefinable
Shallow-copy this object, then apply new definitions to the copy.
127 128 129 130 131 132 |
# File 'lib/graphql/define/instance_definable.rb', line 127 def redefine(**kwargs, &block) ensure_defined new_inst = self.dup new_inst.define(**kwargs, &block) new_inst end |