Commit 14798b8e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

symbolize keys for Gitlab::Git::Diff & Gitlab::Git::Commit

parent d7d8edf3
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def serialize_keys def serialize_keys
%w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids) @serialize_keys ||= %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids).map(&:to_sym)
end end
def sha def sha
...@@ -116,8 +116,10 @@ module Gitlab ...@@ -116,8 +116,10 @@ module Gitlab
end end
def init_from_hash(hash) def init_from_hash(hash)
raw_commit = hash.symbolize_keys
serialize_keys.each do |key| serialize_keys.each do |key|
send(:"#{key}=", hash[key]) send(:"#{key}=", raw_commit[key.to_sym])
end end
end end
end end
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
# Stats properties # Stats properties
attr_accessor :new_file, :renamed_file, :deleted_file attr_accessor :new_file, :renamed_file, :deleted_file
def initialize(raw_diff, head = nil) def initialize(raw_diff)
raise "Nil as raw diff passed" unless raw_diff raise "Nil as raw diff passed" unless raw_diff
if raw_diff.is_a?(Hash) if raw_diff.is_a?(Hash)
...@@ -22,12 +22,10 @@ module Gitlab ...@@ -22,12 +22,10 @@ module Gitlab
else else
init_from_grit(raw_diff) init_from_grit(raw_diff)
end end
@head = head
end end
def serialize_keys def serialize_keys
%w(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file) @serialize_keys ||= %w(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file).map(&:to_sym)
end end
def to_hash def to_hash
...@@ -53,8 +51,10 @@ module Gitlab ...@@ -53,8 +51,10 @@ module Gitlab
end end
def init_from_hash(hash) def init_from_hash(hash)
raw_diff = hash.symbolize_keys
serialize_keys.each do |key| serialize_keys.each do |key|
send(:"#{key}=", hash[key]) send(:"#{key}=", raw_diff[key.to_sym])
end end
end end
end end
......
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