Class: DocVault::DocumentSerializer
- Inherits:
-
Object
- Object
- DocVault::DocumentSerializer
- Defined in:
- lib/doc_vault/document_serializer.rb
Class Method Summary collapse
Class Method Details
.deserialize(data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/doc_vault/document_serializer.rb', line 19 def self.deserialize(data) parsed = JSON.parse(data) case parsed["type"] when "file" deserialize_file(parsed) when "string" parsed["content"] else raise ArgumentError, "Unknown document type: #{parsed["type"]}" end rescue JSON::ParserError raise ArgumentError, "Invalid serialized document data" end |
.serialize(document) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/doc_vault/document_serializer.rb', line 8 def self.serialize(document) case document when File, Tempfile serialize_file(document) when String serialize_string(document) else raise ArgumentError, "Document must be a String, File, or Tempfile" end end |