Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/parse/model/file.rb,
lib/parse/model/object.rb
Overview
Adds extensions to Hash class.
Direct Known Subclasses
Instance Method Summary collapse
-
#parse_file? ⇒ Boolean
Determines whether the hash contains Parse File JSON metadata fields.
-
#parse_object ⇒ Parse::Object
Turns a Parse formatted JSON hash into a Parse-Stack class object, if one is found.
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) withname == 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.
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_object ⇒ Parse::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.
2066 2067 2068 |
# File 'lib/parse/model/object.rb', line 2066 def parse_object Parse::Object.build(self) end |