Class: Rubyprot::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyprot/serializer.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.serialize(object) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubyprot/serializer.rb', line 3

def self.serialize(object)
  raise "Dump path attribute must be set" if Rubyprot.dump_path.nil?
  
  if object.is_a?(Array) then
    if object[0].class.name.rindex("s") == object[0].class.name.length - 1
      plural_string = "es"
    else
      plural_string = "s"
    end
    file_name = object[0].class.name + plural_string
  else       
    file_name = object.class.name
  end
    file = File.new(Rubyprot.dump_path + "/" + file_name, "w")
    file.write(Marshal.dump(object))
    file.close    
  
  file_name
end