Module: GraphQL::Define::InstanceDefinable::ClassMethods

Defined in:
lib/graphql/define/instance_definable.rb

Instance Method Summary collapse

Instance Method Details

#accepts_definitions(*accepts) ⇒ Object

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.



59
60
61
# File 'lib/graphql/define/instance_definable.rb', line 59

def accepts_definitions(*accepts)
  @own_dictionary = own_dictionary.merge(AssignmentDictionary.create(*accepts))
end

#define(&block) ⇒ Object

Define an instance of this class using its definitions.



49
50
51
52
53
54
# File 'lib/graphql/define/instance_definable.rb', line 49

def define(&block)
  instance = self.new
  proxy = DefinedObjectProxy.new(instance, dictionary)
  block && proxy.instance_eval(&block)
  instance
end

#dictionaryHash

Returns combined definitions for self and ancestors.

Returns:

  • (Hash)

    combined definitions for self and ancestors



64
65
66
67
68
69
70
# File 'lib/graphql/define/instance_definable.rb', line 64

def dictionary
  if superclass.respond_to?(:dictionary)
    own_dictionary.merge(superclass.dictionary)
  else
    own_dictionary
  end
end

#own_dictionaryHash

Returns definitions for this class only.

Returns:

  • (Hash)

    definitions for this class only



73
74
75
# File 'lib/graphql/define/instance_definable.rb', line 73

def own_dictionary
  @own_dictionary ||= {}
end