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.



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/graphql/define/instance_definable.rb', line 235

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) ⇒ Object

Create a new instance and prepare a definition using its definitions.

Parameters:

  • kwargs (Hash)

    Key-value pairs corresponding to defininitions from accepts_definitions

  • block (Proc)

    Block which calls helper methods from accepts_definitions



226
227
228
229
230
# File 'lib/graphql/define/instance_definable.rb', line 226

def define(**kwargs, &block)
  instance = self.new
  instance.define(**kwargs, &block)
  instance
end

#dictionaryHash

Returns combined definitions for self and ancestors

Returns:

  • (Hash)

    combined definitions for self and ancestors



265
266
267
268
269
270
271
# File 'lib/graphql/define/instance_definable.rb', line 265

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

#ensure_defined(*method_names) ⇒ Object



249
250
251
252
253
# File 'lib/graphql/define/instance_definable.rb', line 249

def ensure_defined(*method_names)
  @ensure_defined_method_names ||= []
  @ensure_defined_method_names.concat(method_names)
  nil
end

#ensure_defined_method_namesObject



255
256
257
258
259
260
261
262
# File 'lib/graphql/define/instance_definable.rb', line 255

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_dictionaryHash

Returns definitions for this class only

Returns:

  • (Hash)

    definitions for this class only



274
275
276
# File 'lib/graphql/define/instance_definable.rb', line 274

def own_dictionary
  @own_dictionary ||= {}
end