Class: Hash

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

Overview

Adds extensions to Hash class.

Direct Known Subclasses

Parse::Embeddings::ProviderRegistry

Instance Method Summary collapse

Instance Method Details

#parse_file?Boolean

Determines whether the hash contains Parse File JSON metadata fields.

Accepts the canonical Parse Server file-pointer shapes:

  • {name, url} (count == 2) with name == File.basename(url path)
  • {__type: "File", name, url} (any count) with the same basename equality

The URL's query string is stripped before computing basename so short-TTL presigned URLs that Parse Server's S3FilesAdapter returns on every read don't include the signature bytes in the comparison.

Returns:

  • (Boolean)

    True if this hash contains Parse file metadata.



1036
1037
1038
1039
1040
1041
1042
1043
# File 'lib/parse/model/file.rb', line 1036

def parse_file?
  url = self[Parse::File::FIELD_URL]
  name = self[Parse::File::FIELD_NAME]
  return false unless url.present? && name.present?
  return false unless count == 2 || self["__type"] == Parse::File.parse_class
  path_only = Parse::File.strip_query(url)
  name == ::File.basename(path_only)
end

#parse_objectParse::Object

Turns a Parse formatted JSON hash into a Parse-Stack class object, if one is found. This is equivalent to calling Parse::Object.build on the hash object itself, but allows for doing this in loops, such as map when using symbol to proc. However, you can also use the Array extension Array#parse_objects for doing that more safely.

Returns:

  • (Parse::Object)

    A Parse::Object subclass represented the built class.



2066
2067
2068
# File 'lib/parse/model/object.rb', line 2066

def parse_object
  Parse::Object.build(self)
end