From 14798b8e686aafaa9ea3bc9b18294fefa54801f5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 16 Apr 2013 16:29:49 +0300 Subject: [PATCH] symbolize keys for Gitlab::Git::Diff & Gitlab::Git::Commit --- lib/gitlab/git/commit.rb | 6 ++++-- lib/gitlab/git/diff.rb | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index e5e48ec..a92c21a 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -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 diff --git a/lib/gitlab/git/diff.rb b/lib/gitlab/git/diff.rb index d922585..45191dd 100644 --- a/lib/gitlab/git/diff.rb +++ b/lib/gitlab/git/diff.rb @@ -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 -- libgit2 0.21.2