module GraphQL::Define::InstanceDefinable::ClassMethods

Public Instance Methods

accepts_definitions(*accepts) click to toggle source

Attach definitions to this class. Each symbol in `accepts` will be assigned with `{key}=`. The last entry in accepts may be a hash of name-proc pairs for custom definitions.

# File lib/graphql/define/instance_definable.rb, line 232
def accepts_definitions(*accepts)
  new_assignments = if accepts.last.is_a?(Hash)
    accepts.pop.dup
  else
    {}
  end

  accepts.each do |key|
    new_assignments[key] = AssignAttribute.new(key)
  end

  @own_dictionary = own_dictionary.merge(new_assignments)
end
define(**kwargs, &block) click to toggle source

Create a new instance and prepare a definition using its {.definitions}. @param kwargs [Hash] Key-value pairs corresponding to defininitions from `accepts_definitions` @param block [Proc] Block which calls helper methods from `accepts_definitions`

# File lib/graphql/define/instance_definable.rb, line 223
def define(**kwargs, &block)
  instance = self.new
  instance.define(**kwargs, &block)
  instance
end
dictionary() click to toggle source

@return [Hash] combined definitions for self and ancestors

# File lib/graphql/define/instance_definable.rb, line 262
def dictionary
  if superclass.respond_to?(:dictionary)
    own_dictionary.merge(superclass.dictionary)
  else
    own_dictionary
  end
end
ensure_defined(*method_names) click to toggle source
# File lib/graphql/define/instance_definable.rb, line 246
def ensure_defined(*method_names)
  @ensure_defined_method_names ||= []
  @ensure_defined_method_names.concat(method_names)
  nil
end
ensure_defined_method_names() click to toggle source
# File lib/graphql/define/instance_definable.rb, line 252
def ensure_defined_method_names
  own_method_names = @ensure_defined_method_names || []
  if superclass.respond_to?(:ensure_defined_method_names)
    superclass.ensure_defined_method_names + own_method_names
  else
    own_method_names
  end
end
own_dictionary() click to toggle source

@return [Hash] definitions for this class only

# File lib/graphql/define/instance_definable.rb, line 271
def own_dictionary
  @own_dictionary ||= {}
end