Commit 82c8c42a authored by randx's avatar randx

Move all serialization to marshall

parent 11e4709f
......@@ -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
#
......
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
......@@ -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
#
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment