Method: Parse::Model.find_class

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

.find_class(str) ⇒ Parse::Object

Find a Parse::Model subclass matching this type or Pares collection name. This helper method is useful to find the corresponding class ruby Parse::Object subclass that handles the provided parse class.

Examples:

Parse::Model.find_class('_User') # => Parse::User
Parse::Model.find_class('_Date') # => Parse::Date
Parse::Model.find_class('Installation') # => Parse::Installation

class Artist < Parse::Object
  parse_class "Musician"
end

Parse::Model.find_class("Musician") # => Artist

Parameters:

  • str (String)

    the class name

Returns:

  • (Parse::Object)

    a Parse::Object subclass or a specific Parse type.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/parse/model/model.rb', line 135

def self.find_class(str)
  return Parse::File if str == TYPE_FILE
  return Parse::GeoPoint if str == TYPE_GEOPOINT
  return Parse::Date if str == TYPE_DATE
  return Parse::Bytes if str == TYPE_BYTES
  # return Parse::User if str == "User"
  # return Parse::Installation if str == "Installation"

  str = str.to_s
  # Basically go through all Parse::Object subclasses and see who is has a parse_class
  # set to this string. We will cache the results for future use.
  @@model_cache[str] ||= Parse::Object.descendants.find do |f|
    f.parse_class == str || f.parse_class == "_#{str}"
  end
end