lib/rails/graphql/schema.rb
# Helper to create objects that are actually classes of a given
# +superclass+ ensuring that it inherits from +base_class+.
#
# The +suffix+ option can ensures that the name of the created
# class ends with a specific suffix.
Helper to create objects that are actually classes of a given
+superclass+ ensuring that it inherits from +base_class+.

The +suffix+ option can ensures that the name of the created
class ends with a specific suffix.
Helper to create objects that are actually classes of a given + superclass + ensuring that it inherits from + base_class + . The + suffix + option can ensures that the name of the created class ends with a specific suffix .
def create_klass(name_or_object, superclass, base_class = nil, **xargs, &block)
            name = name_or_object.is_a?(Module) ? name_or_object.name : name_or_object.to_s
            base_module = name.classify.deconstantize
            base_module.prepend('GraphQL::') unless base_module =~ /^GraphQL(::|$)/
            base_module = base_module.delete_suffix('::').constantize
            klass_name = name.classify.demodulize
            klass_name += xargs[:suffix] if xargs.key?(:suffix) &&
              !klass_name.ends_with?(xargs[:suffix])
            if base_module.const_defined?(klass_name)
              klass = base_module.const_get(klass_name)
              raise DuplicatedError, <<~MSG.squish unless !xargs[:once] && klass < superclass
                A constant named "#{klass_name}" already exists for the
                "#{base_module.name}" module.
              MSG
            else
              base_class ||= superclass.ancestors.find { |k| k.superclass === Class }
              valid = superclass.is_a?(Module) && superclass < base_class
              raise DefinitionError, <<~MSG.squish unless valid
                The given "#{superclass}" superclass does not inherites from
                #{base_class.name} class.
              MSG
              klass = base_module.const_set(klass_name, Class.new(superclass))
            end
            klass.abstract = xargs[:abstract] if xargs.key?(:abstract)
            klass.assigned_to = name_or_object if name_or_object.is_a?(Module) &&
              klass.is_a?(Helpers::WithAssignment)
            klass.set_namespace(namespace)
            klass.instance_exec(&block) if block.present?
            klass
          end
def create_klass ( name_or_object , superclass , base_class = nil , ** xargs , & block ) name = name_or_object . is_a? ( Module ) ? name_or_object . name : name_or_object . to_s base_module = name . classify . deconstantize base_module . prepend ( 'GraphQL::' ) unless base_module =~ / ^GraphQL(::|$) / base_module = base_module . delete_suffix ( '::' ) . constantize klass_name = name . classify . demodulize klass_name += xargs [ :suffix ] if xargs . key? ( :suffix ) && ! klass_name . ends_with? ( xargs [ :suffix ] ) if base_module . const_defined? ( klass_name ) klass = base_module . const_get ( klass_name ) raise DuplicatedError , <<~MSG . squish unless ! xargs [ :once ] && klass < superclass 
                A constant named " #{ klass_name } " already exists for the
                " #{ base_module . name } " module.
               MSG else base_class ||= superclass . ancestors . find { | k | k . superclass === Class } valid = superclass . is_a? ( Module ) && superclass < base_class raise DefinitionError , <<~MSG . squish unless valid 
                The given " #{ superclass } " superclass does not inherites from
                 #{ base_class . name }  class.
               MSG klass = base_module . const_set ( klass_name , Class . new ( superclass ) ) end klass . abstract = xargs [ :abstract ] if xargs . key? ( :abstract ) klass . assigned_to = name_or_object if name_or_object . is_a? ( Module ) && klass . is_a? ( Helpers :: WithAssignment ) klass . set_namespace ( namespace ) klass . instance_exec ( & block ) if block . present? klass end
Helper to create objects that are actually classes of a given
+superclass+ ensuring that it inherits from +base_class+.
Helper to create objects that are actually classes of a given + superclass + ensuring that it inherits from + base_class + .
name_or_object
superclass
base_class
xargs
block