diff options
author | Sato Hiroyuki <sathiroyuki@gmail.com> | 2013-04-14 16:08:16 +0400 |
---|---|---|
committer | Sato Hiroyuki <sathiroyuki@gmail.com> | 2013-05-13 13:41:04 +0400 |
commit | 97a9c2293affaeeba6f448b8760bb5dffd170f2c (patch) | |
tree | 4ac47980672bd8589afaeb9457e58b6178284224 /lib | |
parent | edcdbd671b3a1f01f0e1052d5867e4a14c90278b (diff) |
Refactor: remove dup code
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extracts_path.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 1b7c698d0a8..6025bb2a9f6 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -94,16 +94,28 @@ module ExtractsPath # Automatically renders `not_found!` if a valid tree path could not be # resolved (e.g., when a user inserts an invalid path or ref). def assign_ref_vars - @id = params[:id] + @id = get_id @ref, @path = extract_ref(@id) - @commit = @project.repository.commit(@ref) + @repo = @project.repository - @tree = Tree.new(@project.repository, @commit.id, @ref, @path) + @commit = @repo.commit(@ref) + + @tree = Tree.new(@repo, @commit.id, @ref, @path) + @hex_path = Digest::SHA1.hexdigest(@path) + @logs_path = logs_file_project_ref_path(@project, @ref, @path) raise InvalidPathError unless @tree.exists? rescue RuntimeError, NoMethodError, InvalidPathError not_found! end + + private + + def get_id + id = params[:id] || params[:ref] + id += "/" + params[:path] unless params[:path].blank? + id + end end |