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.



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

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



224
225
226
227
228
# File 'lib/graphql/define/instance_definable.rb', line 224

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



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

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

#ensure_defined(*method_names) ⇒ Object



247
248
249
250
251
# File 'lib/graphql/define/instance_definable.rb', line 247

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

#ensure_defined_method_namesObject



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

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



272
273
274
# File 'lib/graphql/define/instance_definable.rb', line 272

def own_dictionary
  @own_dictionary ||= {}
end