From 90b220ddda28d69bb1109871a77e2f8d80ab5aa6 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Sun, 23 Sep 2018 12:06:06 +0200 Subject: [PATCH] Format according to Houndbot #4 --- app/controllers/teams_controller.rb | 1 - app/models/table.rb | 4 ++-- app/models/team_zip_export.rb | 27 +++++++++++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 5026853b2..f31d9aa04 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -289,5 +289,4 @@ class TeamsController < ApplicationController :samples ) end - end diff --git a/app/models/table.rb b/app/models/table.rb index c48526123..6df0bcfae 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -135,8 +135,8 @@ class Table < ApplicationRecord data = JSON.parse(contents)['data'] CSV.generate do |csv| data.each do |row| - csv << row - end + csv << row + end end end end diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index 0c5d3b490..04eea87b3 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -4,7 +4,8 @@ require 'csv' class TeamZipExport < ZipExport has_attached_file :zip_file, - path: '/zip_exports/:attachment/:id_partition/:hash/:style/:filename' + path: '/zip_exports/:attachment/:id_partition/' \ + ':hash/:style/:filename' validates_attachment :zip_file, content_type: { content_type: 'application/zip' } @@ -19,10 +20,8 @@ class TeamZipExport < ZipExport ).first output_file = File.new( File.join(Rails.root, - "tmp/zip-ready/projects_export-timestamp-#{Time.now.to_i}.zip" - ), - 'w+' - ) + "tmp/zip-ready/projects_export-timestamp-#{Time.now.to_i}.zip"), + 'w+') fill_content(dir_to_zip, data, type, options) zip!(dir_to_zip, output_file.path) self.zip_file = File.open(output_file) @@ -34,9 +33,9 @@ class TeamZipExport < ZipExport private # Export all functionality - def generate_teams_zip(tmp_dir, data, _options = {}) + def generate_teams_zip(tmp_dir, data, options = {}) # Create team folder - @team = _options[:team] + @team = options[:team] team_path = "#{tmp_dir}/#{handle_name(@team.name)}" FileUtils.mkdir_p(team_path) @@ -47,8 +46,12 @@ class TeamZipExport < ZipExport # Iterate through every project data.each_with_index do |(_, p), ind| project_name = handle_name(p.name) + "_#{ind}" - root = p.archived ? "#{team_path}/Archived projects" : - "#{team_path}/Projects" + root = + if p.archived + "#{team_path}/Archived projects" + else + "#{team_path}/Projects" + end root += "/#{project_name}" FileUtils.mkdir_p(root) @@ -60,8 +63,8 @@ class TeamZipExport < ZipExport # Find all assigned inventories through all tasks in the project task_ids = p.project_my_modules repo_rows = RepositoryRow.joins(:my_modules) - .where(my_modules: { id: task_ids }) - .distinct + .where(my_modules: { id: task_ids }) + .distinct # Iterate through every inventory repo and save it to CSV repo_rows.map(&:repository).uniq.each_with_index do |repo, repo_ind| @@ -128,7 +131,7 @@ class TeamZipExport < ZipExport # Remove control characters name = name.chars.map(&:ord).select { |s| (s > 31 && s < 127) || s > 127 } - .pack('U*') + .pack('U*') # Remove leading hyphens, trailing dots/spaces name.gsub(/^-|\.+$| +$/, '_')