module GraphQL::Define::InstanceDefinable
def self.included(base)
def self.included(base) base.extend(ClassMethods) base.ensure_defined(:metadata) end
def define(**kwargs, &block)
-
(void)
-
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
def ensure_defined
-
(void)
-
def ensure_defined if @pending_definition defn = @pending_definition @pending_definition = nil revive_dependent_methods begin defn_proxy = DefinedObjectProxy.new(self) # Apply definition from `define(...)` kwargs defn.define_keywords.each do |keyword, value| defn_proxy.public_send(keyword, value) end # and/or apply definition from `define { ... }` block if defn.define_proc defn_proxy.instance_eval(&defn.define_proc) end rescue StandardError # The definition block failed to run, so make this object pending again: stash_dependent_methods @pending_definition = defn raise end end nil end
def initialize_copy(other)
def initialize_copy(other) super @metadata = other.metadata.dup end
def metadata
-
(Hash
- Hash for user-defined storage
def metadata @metadata ||= {} end
def redefine(**kwargs, &block)
-
(InstanceDefinable)
- A new instance, with any extended definitions
Other tags:
- See: {#define} - for arguments
def redefine(**kwargs, &block) ensure_defined new_inst = self.dup new_inst.define(**kwargs, &block) new_inst end
def revive_dependent_methods
-
(void)
-
def revive_dependent_methods pending_methods = @pending_methods self.singleton_class.class_eval { pending_methods.each do |method| undef_method(method.name) if method_defined?(method.name) define_method(method.name, method) end } @pending_methods = nil end
def stash_dependent_methods
-
(void)
-
def stash_dependent_methods method_names = self.class.ensure_defined_method_names @pending_methods = method_names.map { |n| self.class.instance_method(n) } self.singleton_class.class_eval do method_names.each do |method_name| undef_method(method_name) if method_defined?(method_name) define_method(method_name) { |*args, &block| ensure_defined self.send(method_name, *args, &block) } end end end