From a82167fe4c83aa9e269621af8ac3d09e9a7e79a9 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Feb 2013 13:21:05 +0400 Subject: [PATCH] #907: remove #destroy_file_from_file_store method, refactoring --- app/models/project.rb | 2 +- lib/modules/models/file_store_clean.rb | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 967291943..9acb8eaaf 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -209,7 +209,7 @@ class Project < ActiveRecord::Base return nil if resp['sha1_hash'].nil? end if project_tag - project_tag.destroy_file_from_file_store(project_tag.sha1) + project_tag.destroy_files_from_file_store(project_tag.sha1) project_tag.update_attributes(:sha1 => sha1) else project_tags.create( diff --git a/lib/modules/models/file_store_clean.rb b/lib/modules/models/file_store_clean.rb index 06db3fb89..97e86fa69 100644 --- a/lib/modules/models/file_store_clean.rb +++ b/lib/modules/models/file_store_clean.rb @@ -15,21 +15,18 @@ module Modules raise NotImplementedError, "You should implement this method" end - def destroy_files_from_file_store - sha1_of_file_store_files.each do |sha1| - destroy_file_from_file_store sha1 - end - end - - def destroy_file_from_file_store(sha1) + def destroy_files_from_file_store(args = sha1_of_file_store_files) + files = *args token = User.system.find_by_uname('file_store').authentication_token - uri = URI APP_CONFIG['file_store_url'] + uri = URI APP_CONFIG['file_store_url'] Net::HTTP.start(uri.host, uri.port) do |http| - begin - req = Net::HTTP::Delete.new("/api/v1/file_stores/#{sha1}.json") - req.basic_auth token, '' - http.request(req) - rescue # Dont care about it + files.each do |sha1| + begin + req = Net::HTTP::Delete.new("/api/v1/file_stores/#{sha1}.json") + req.basic_auth token, '' + http.request(req) + rescue # Dont care about it + end end end end