Module: GraphQL::Define::InstanceDefinable
- Included in:
- Argument, BaseType, GraphQL::Directive, Field, Relay::GlobalNodeIdentification, Relay::Mutation
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#definition_proc=(defn_block) ⇒ Object
Set the definition block for this instance.
-
#metadata ⇒ Hash<Object, Object>
‘metadata` can store arbitrary key-values with an object.
Class Method Details
.included(base) ⇒ Object
60 61 62 |
# File 'lib/graphql/define/instance_definable.rb', line 60 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#definition_proc=(defn_block) ⇒ Object
Set the definition block for this instance. It can be run later with #ensure_defined
66 67 68 |
# File 'lib/graphql/define/instance_definable.rb', line 66 def definition_proc=(defn_block) @definition_proc = defn_block end |
#metadata ⇒ Hash<Object, Object>
‘metadata` can store arbitrary key-values with an object.
73 74 75 76 |
# File 'lib/graphql/define/instance_definable.rb', line 73 def ensure_defined @metadata ||= {} end |