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

This commit is contained in:
Dmitriy Zaporozhets 2013-04-16 16:29:49 +03:00
parent d7d8edf3ca
commit 14798b8e68
2 changed files with 9 additions and 7 deletions

View File

@ -25,7 +25,7 @@ module Gitlab
end
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
def sha
@ -116,8 +116,10 @@ module Gitlab
end
def init_from_hash(hash)
raw_commit = hash.symbolize_keys
serialize_keys.each do |key|
send(:"#{key}=", hash[key])
send(:"#{key}=", raw_commit[key.to_sym])
end
end
end

View File

@ -14,7 +14,7 @@ module Gitlab
# Stats properties
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
if raw_diff.is_a?(Hash)
@ -22,12 +22,10 @@ module Gitlab
else
init_from_grit(raw_diff)
end
@head = head
end
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
def to_hash
@ -53,8 +51,10 @@ module Gitlab
end
def init_from_hash(hash)
raw_diff = hash.symbolize_keys
serialize_keys.each do |key|
send(:"#{key}=", hash[key])
send(:"#{key}=", raw_diff[key.to_sym])
end
end
end