Class: Cheatorious::Utils
- Inherits:
-
Object
- Object
- Cheatorious::Utils
- Defined in:
- lib/cheatorious/utils.rb
Class Method Summary collapse
- .deserialize(data, from = nil) ⇒ Object
- .serialization_type(data) ⇒ Object
- .serialize(object, to = nil) ⇒ Object
Class Method Details
.deserialize(data, from = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/cheatorious/utils.rb', line 11 def self.deserialize(data, from = nil) data = Base64.decode64(data) if from == :base64 object = Marshal.load(data) return object end |
.serialization_type(data) ⇒ Object
17 18 19 |
# File 'lib/cheatorious/utils.rb', line 17 def self.serialization_type(data) /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/ =~ data ? :base64 : :bytes end |
.serialize(object, to = nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/cheatorious/utils.rb', line 5 def self.serialize(object, to = nil) data = Marshal.dump(object) data = Base64.encode64(data) if to == :base64 return data end |