OSDN Git Service

Move all serialization to marshall
authorrandx <dmitriy.zaporozhets@gmail.com>
Tue, 3 Apr 2012 23:49:58 +0000 (02:49 +0300)
committerrandx <dmitriy.zaporozhets@gmail.com>
Tue, 3 Apr 2012 23:49:58 +0000 (02:49 +0300)
app/models/event.rb
app/models/gitlab_serialize.rb [deleted file]
app/models/merge_request.rb

index a71d598..b7748ce 100644 (file)
@@ -14,7 +14,8 @@ class Event < ActiveRecord::Base
   belongs_to :project
   belongs_to :target, :polymorphic => true
 
-  serialize :data, GitlabSerialize.new
+  # For Hash only
+  serialize :data
 
   scope :recent, order("created_at DESC")
   scope :code_push, where(:action => Pushed)
@@ -104,6 +105,14 @@ class Event < ActiveRecord::Base
   delegate :name, :email, :to => :author, :prefix => true, :allow_nil => true
   delegate :title, :to => :issue, :prefix => true, :allow_nil => true
   delegate :title, :to => :merge_request, :prefix => true, :allow_nil => true
+
+  def load obj 
+    Marshal.load obj
+  end
+
+  def dump obj 
+    Marshal.dump obj
+  end
 end
 # == Schema Information
 #
diff --git a/app/models/gitlab_serialize.rb b/app/models/gitlab_serialize.rb
deleted file mode 100644 (file)
index efd63cc..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-class GitlabSerialize
-  # Called to deserialize data to ruby object.
-  def load(data)
-    hash = parse_data(data)
-    hash = HashWithIndifferentAccess.new(hash) if hash
-    hash
-  end
-
-  def parse_data(data)
-    JSON.load(data)
-  rescue JSON::ParserError
-    begin
-      YAML.load(data)
-    rescue Psych::SyntaxError
-      nil
-    end
-  end
-
-  # Called to convert from ruby object to serialized data.
-  def dump(obj)
-    JSON.dump(obj)
-  end
-end
index edf073d..6ee9b88 100644 (file)
@@ -144,6 +144,14 @@ class MergeRequest < ActiveRecord::Base
       :author_id => user_id
     )
   end
+
+  def load obj 
+    Marshal.load obj
+  end
+
+  def dump obj 
+    Marshal.dump obj
+  end
 end
 # == Schema Information
 #