Method: String#to_parse_class

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

#to_parse_class(singularize: false) ⇒ String

Convert a string to a Parse class name. This method tries to find a responsible Parse::Object subclass that potentially matches the given string. If no match is found, it returns the camelized version of the string. This method is used internally for matching association attributes to registered Parse::Object subclasses. The method can also singularize the name before performing conversion.

Examples:

"users".to_parse_class(singularize: true) # => "_User"
"users".to_parse_class # => "Users"
"song_data".to_parse_class # => "SongData"

Parameters:

  • singularize (Boolean) (defaults to: false)

    whether the string should be singularized first before performing conversion.

Returns:

  • (String)

    the matching Parse class for this string.



194
195
196
197
198
199
200
# File 'lib/parse/model/model.rb', line 194

def to_parse_class(singularize: false)
  final_class = singularize ? self.singularize.camelize : self.camelize
  klass = Parse::Model.find_class(final_class) || Parse::Model.find_class(self)
  #handles the case that a class has a custom parse table
  final_class = klass.parse_class if klass.present?
  final_class
end