Commit 14798b8e686aafaa9ea3bc9b18294fefa54801f5
1 parent
d7d8edf3
Exists in
master
and in
4 other branches
symbolize keys for Gitlab::Git::Diff & Gitlab::Git::Commit
Showing
2 changed files
with
9 additions
and
7 deletions
Show diff stats
lib/gitlab/git/commit.rb
| @@ -25,7 +25,7 @@ module Gitlab | @@ -25,7 +25,7 @@ module Gitlab | ||
| 25 | end | 25 | end |
| 26 | 26 | ||
| 27 | def serialize_keys | 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 | end | 29 | end |
| 30 | 30 | ||
| 31 | def sha | 31 | def sha |
| @@ -116,8 +116,10 @@ module Gitlab | @@ -116,8 +116,10 @@ module Gitlab | ||
| 116 | end | 116 | end |
| 117 | 117 | ||
| 118 | def init_from_hash(hash) | 118 | def init_from_hash(hash) |
| 119 | + raw_commit = hash.symbolize_keys | ||
| 120 | + | ||
| 119 | serialize_keys.each do |key| | 121 | serialize_keys.each do |key| |
| 120 | - send(:"#{key}=", hash[key]) | 122 | + send(:"#{key}=", raw_commit[key.to_sym]) |
| 121 | end | 123 | end |
| 122 | end | 124 | end |
| 123 | end | 125 | end |
lib/gitlab/git/diff.rb
| @@ -14,7 +14,7 @@ module Gitlab | @@ -14,7 +14,7 @@ module Gitlab | ||
| 14 | # Stats properties | 14 | # Stats properties |
| 15 | attr_accessor :new_file, :renamed_file, :deleted_file | 15 | attr_accessor :new_file, :renamed_file, :deleted_file |
| 16 | 16 | ||
| 17 | - def initialize(raw_diff, head = nil) | 17 | + def initialize(raw_diff) |
| 18 | raise "Nil as raw diff passed" unless raw_diff | 18 | raise "Nil as raw diff passed" unless raw_diff |
| 19 | 19 | ||
| 20 | if raw_diff.is_a?(Hash) | 20 | if raw_diff.is_a?(Hash) |
| @@ -22,12 +22,10 @@ module Gitlab | @@ -22,12 +22,10 @@ module Gitlab | ||
| 22 | else | 22 | else |
| 23 | init_from_grit(raw_diff) | 23 | init_from_grit(raw_diff) |
| 24 | end | 24 | end |
| 25 | - | ||
| 26 | - @head = head | ||
| 27 | end | 25 | end |
| 28 | 26 | ||
| 29 | def serialize_keys | 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 | end | 29 | end |
| 32 | 30 | ||
| 33 | def to_hash | 31 | def to_hash |
| @@ -53,8 +51,10 @@ module Gitlab | @@ -53,8 +51,10 @@ module Gitlab | ||
| 53 | end | 51 | end |
| 54 | 52 | ||
| 55 | def init_from_hash(hash) | 53 | def init_from_hash(hash) |
| 54 | + raw_diff = hash.symbolize_keys | ||
| 55 | + | ||
| 56 | serialize_keys.each do |key| | 56 | serialize_keys.each do |key| |
| 57 | - send(:"#{key}=", hash[key]) | 57 | + send(:"#{key}=", raw_diff[key.to_sym]) |
| 58 | end | 58 | end |
| 59 | end | 59 | end |
| 60 | end | 60 | end |