Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/model/model.rb

Overview

Add extensions to the String class.

Instance Method Summary collapse

Instance Method Details

#columnizeString

This method returns a camel-cased version of the string with the first letter of the string in lower case. This is the standard naming convention for Parse columns and property fields. This has special exception to the string “id”, which returns “objectId”. This is the default name filtering method for all defined properties and query keys in Parse::Query.

Examples:

"my_field".columnize # => "myField"
"MyDataColumn".columnize # => "myDataColumn"
"id".columnize # => "objectId" (special)

Returns:

See Also:



168
169
170
171
172
# File 'lib/parse/model/model.rb', line 168

def columnize
  return Parse::Model::OBJECT_ID if self == Parse::Model::ID
  u = "_".freeze
  (first == u ? sub(u, "") : self).camelize(:lower)
end

#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.



188
189
190
191
192
193
194
# File 'lib/parse/model/model.rb', line 188

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