Commit 82c8c42aee8d774053198b4fa4d0e4abc7011a70
1 parent
11e4709f
Exists in
master
and in
4 other branches
Move all serialization to marshall
Showing
3 changed files
with
18 additions
and
24 deletions
Show diff stats
app/models/event.rb
| @@ -14,7 +14,8 @@ class Event < ActiveRecord::Base | @@ -14,7 +14,8 @@ class Event < ActiveRecord::Base | ||
| 14 | belongs_to :project | 14 | belongs_to :project |
| 15 | belongs_to :target, :polymorphic => true | 15 | belongs_to :target, :polymorphic => true |
| 16 | 16 | ||
| 17 | - serialize :data, GitlabSerialize.new | 17 | + # For Hash only |
| 18 | + serialize :data | ||
| 18 | 19 | ||
| 19 | scope :recent, order("created_at DESC") | 20 | scope :recent, order("created_at DESC") |
| 20 | scope :code_push, where(:action => Pushed) | 21 | scope :code_push, where(:action => Pushed) |
| @@ -104,6 +105,14 @@ class Event < ActiveRecord::Base | @@ -104,6 +105,14 @@ class Event < ActiveRecord::Base | ||
| 104 | delegate :name, :email, :to => :author, :prefix => true, :allow_nil => true | 105 | delegate :name, :email, :to => :author, :prefix => true, :allow_nil => true |
| 105 | delegate :title, :to => :issue, :prefix => true, :allow_nil => true | 106 | delegate :title, :to => :issue, :prefix => true, :allow_nil => true |
| 106 | delegate :title, :to => :merge_request, :prefix => true, :allow_nil => true | 107 | delegate :title, :to => :merge_request, :prefix => true, :allow_nil => true |
| 108 | + | ||
| 109 | + def load obj | ||
| 110 | + Marshal.load obj | ||
| 111 | + end | ||
| 112 | + | ||
| 113 | + def dump obj | ||
| 114 | + Marshal.dump obj | ||
| 115 | + end | ||
| 107 | end | 116 | end |
| 108 | # == Schema Information | 117 | # == Schema Information |
| 109 | # | 118 | # |
app/models/gitlab_serialize.rb
| @@ -1,23 +0,0 @@ | @@ -1,23 +0,0 @@ | ||
| 1 | -class GitlabSerialize | ||
| 2 | - # Called to deserialize data to ruby object. | ||
| 3 | - def load(data) | ||
| 4 | - hash = parse_data(data) | ||
| 5 | - hash = HashWithIndifferentAccess.new(hash) if hash | ||
| 6 | - hash | ||
| 7 | - end | ||
| 8 | - | ||
| 9 | - def parse_data(data) | ||
| 10 | - JSON.load(data) | ||
| 11 | - rescue JSON::ParserError | ||
| 12 | - begin | ||
| 13 | - YAML.load(data) | ||
| 14 | - rescue Psych::SyntaxError | ||
| 15 | - nil | ||
| 16 | - end | ||
| 17 | - end | ||
| 18 | - | ||
| 19 | - # Called to convert from ruby object to serialized data. | ||
| 20 | - def dump(obj) | ||
| 21 | - JSON.dump(obj) | ||
| 22 | - end | ||
| 23 | -end |
app/models/merge_request.rb
| @@ -144,6 +144,14 @@ class MergeRequest < ActiveRecord::Base | @@ -144,6 +144,14 @@ class MergeRequest < ActiveRecord::Base | ||
| 144 | :author_id => user_id | 144 | :author_id => user_id |
| 145 | ) | 145 | ) |
| 146 | end | 146 | end |
| 147 | + | ||
| 148 | + def load obj | ||
| 149 | + Marshal.load obj | ||
| 150 | + end | ||
| 151 | + | ||
| 152 | + def dump obj | ||
| 153 | + Marshal.dump obj | ||
| 154 | + end | ||
| 147 | end | 155 | end |
| 148 | # == Schema Information | 156 | # == Schema Information |
| 149 | # | 157 | # |