Commit 14798b8e686aafaa9ea3bc9b18294fefa54801f5

Authored by Dmitriy Zaporozhets
1 parent d7d8edf3

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

lib/gitlab/git/commit.rb
... ... @@ -25,7 +25,7 @@ module Gitlab
25 25 end
26 26  
27 27 def serialize_keys
28   - %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids)
  28 + @serialize_keys ||= %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids).map(&:to_sym)
29 29 end
30 30  
31 31 def sha
... ... @@ -116,8 +116,10 @@ module Gitlab
116 116 end
117 117  
118 118 def init_from_hash(hash)
  119 + raw_commit = hash.symbolize_keys
  120 +
119 121 serialize_keys.each do |key|
120   - send(:"#{key}=", hash[key])
  122 + send(:"#{key}=", raw_commit[key.to_sym])
121 123 end
122 124 end
123 125 end
... ...
lib/gitlab/git/diff.rb
... ... @@ -14,7 +14,7 @@ module Gitlab
14 14 # Stats properties
15 15 attr_accessor :new_file, :renamed_file, :deleted_file
16 16  
17   - def initialize(raw_diff, head = nil)
  17 + def initialize(raw_diff)
18 18 raise "Nil as raw diff passed" unless raw_diff
19 19  
20 20 if raw_diff.is_a?(Hash)
... ... @@ -22,12 +22,10 @@ module Gitlab
22 22 else
23 23 init_from_grit(raw_diff)
24 24 end
25   -
26   - @head = head
27 25 end
28 26  
29 27 def serialize_keys
30   - %w(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file)
  28 + @serialize_keys ||= %w(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file).map(&:to_sym)
31 29 end
32 30  
33 31 def to_hash
... ... @@ -53,8 +51,10 @@ module Gitlab
53 51 end
54 52  
55 53 def init_from_hash(hash)
  54 + raw_diff = hash.symbolize_keys
  55 +
56 56 serialize_keys.each do |key|
57   - send(:"#{key}=", hash[key])
  57 + send(:"#{key}=", raw_diff[key.to_sym])
58 58 end
59 59 end
60 60 end
... ...