Module: Parse::PluralizedAliases

Defined in:
lib/parse/model/core/pluralized_aliases.rb

Overview

Global const_missing hook that lazily resolves the plural form of a Object subclass constant to that class. Referencing Posts when a class Post exists installs Posts as an alias for Post on the referencing module and returns it, so query entry points like Posts.where(...).count work without any per-model boilerplate.

The hook is prepended onto Module so it applies to constant lookups in any namespace (top-level and nested). It is tightly guarded: every path that is not a plural-of-a-Parse-class falls through to super, preserving normal NameError and autoloader (Zeitwerk/classic) behavior. The whole feature is gated on pluralized_aliases? so opting out (Parse.pluralized_aliases = false) makes this a near-zero cost pass-through.

See Also:

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object



22
23
24
25
26
# File 'lib/parse/model/core/pluralized_aliases.rb', line 22

def const_missing(name)
  klass = Parse.__pluralized_alias_for(self, name) if defined?(Parse)
  return klass unless klass.nil?
  super
end