From b58c057ede61f090cd999a5eeda076d232a6cfc5 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 15:24:42 -0700 Subject: [PATCH 1/8] rubocop --auto-correct --only=Layout --- app/mailers/job_mailer.rb | 1 - app/models/bundle_context.rb | 3 +- config/initializers/config.rb | 1 - config/initializers/simple_form.rb | 3 +- config/initializers/simple_form_bootstrap.rb | 7 ----- .../bundle_contexts_controller_spec.rb | 29 ++++++++++--------- spec/models/bundle_context_spec.rb | 6 ++-- spec/services/discovery_report_spec.rb | 2 +- spec/spec_helper.rb | 1 - .../job_runs/index.json.jbuilder_spec.rb | 14 ++++----- 10 files changed, 29 insertions(+), 38 deletions(-) diff --git a/app/mailers/job_mailer.rb b/app/mailers/job_mailer.rb index 1b45dc57..d46fccca 100644 --- a/app/mailers/job_mailer.rb +++ b/app/mailers/job_mailer.rb @@ -6,5 +6,4 @@ def completion_email @user = @job_run.bundle_context.user mail(to: @user.email, subject: 'Your pre-assembly job has completed') end - end diff --git a/app/models/bundle_context.rb b/app/models/bundle_context.rb index 9bb3c9ab..6d4250fc 100644 --- a/app/models/bundle_context.rb +++ b/app/models/bundle_context.rb @@ -5,7 +5,7 @@ class BundleContext < ApplicationRecord validates :bundle_dir, :content_metadata_creation, :content_structure, presence: true validates :project_name, presence: true, format: { with: /\A[\w-]+\z/, - message: "only allows A-Z, a-z, 0-9, hyphen and underscore" } + message: "only allows A-Z, a-z, 0-9, hyphen and underscore" } validates :staging_style_symlink, inclusion: { in: [true, false] } validate :verify_bundle_directory @@ -29,7 +29,6 @@ class BundleContext < ApplicationRecord accepts_nested_attributes_for :job_runs - # return [PreAssembly::Bundle] def bundle @bundle ||= PreAssembly::Bundle.new(self) diff --git a/config/initializers/config.rb b/config/initializers/config.rb index 776c6b51..623201d3 100644 --- a/config/initializers/config.rb +++ b/config/initializers/config.rb @@ -46,5 +46,4 @@ # required(:age).maybe(:int?) # required(:email).filled(format?: EMAIL_REGEX) # end - end diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 83718ead..d3520155 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Uncomment this and change the path if necessary to include your own # components. @@ -14,7 +15,7 @@ # stack. The options given below are used to wrap the # whole input. config.wrappers :default, class: :input, - hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b| + hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b| ## Extensions enabled by default # Any of these extensions can be disabled for a # given input by passing: `f.input EXTENSION_NAME => false`. diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index 0178fd53..85c144ac 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -45,7 +45,6 @@ config.input_field_error_class = 'is-invalid' config.input_field_valid_class = 'is-valid' - # vertical forms # # vertical default_wrapper @@ -136,7 +135,6 @@ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } end - # horizontal forms # # horizontal default_wrapper @@ -240,7 +238,6 @@ end end - # inline forms # # inline default_wrapper @@ -269,7 +266,6 @@ b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } end - # bootstrap custom forms # # custom input for boolean @@ -359,7 +355,6 @@ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } end - # Input Group - custom component # see example app and config at https://github.com/rafaelfranca/simple_form-bootstrap # config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| @@ -380,7 +375,6 @@ # b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } # end - # Floating Labels form # # floating labels default_wrapper @@ -408,7 +402,6 @@ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } end - # The default wrapper to be used by the FormBuilder. config.default_wrapper = :vertical_form diff --git a/spec/controllers/bundle_contexts_controller_spec.rb b/spec/controllers/bundle_contexts_controller_spec.rb index 739d330c..0a713a99 100644 --- a/spec/controllers/bundle_contexts_controller_spec.rb +++ b/spec/controllers/bundle_contexts_controller_spec.rb @@ -19,7 +19,6 @@ end end - context 'users persisted in db' do before { sign_in(create :user) } @@ -62,7 +61,7 @@ it "fails if job_type is nil" do Dir.delete(output_dir) if Dir.exist?(output_dir) - params[:bundle_context].merge!(job_runs_attributes: {"0" => { job_type: "" }}) + params[:bundle_context].merge!(job_runs_attributes: { "0" => { job_type: "" } }) expect { post :create, params: params }.not_to change(JobRun, :count) end end @@ -71,18 +70,20 @@ it 'do not create objects' do params[:bundle_context].merge!(project_name: nil) expect { post :create, params: params }.not_to change(BundleContext, :count) - expect { post :create, params: { bundle_context: { - project_name: '', - content_structure: '', - content_metadata_creation: '', - bundle_dir: '' - }}}.not_to change(BundleContext, :count) - expect { post :create, params: { bundle_context: { - project_name: "SMPL's folly", - content_structure: '', - content_metadata_creation: '', - bundle_dir: '' - }}}.not_to change(BundleContext, :count) + expect { + post :create, params: { bundle_context: { + project_name: '', + content_structure: '', + content_metadata_creation: '', + bundle_dir: '' + } }}.not_to change(BundleContext, :count) + expect { + post :create, params: { bundle_context: { + project_name: "SMPL's folly", + content_structure: '', + content_metadata_creation: '', + bundle_dir: '' + } }}.not_to change(BundleContext, :count) end end end diff --git a/spec/models/bundle_context_spec.rb b/spec/models/bundle_context_spec.rb index 3457f855..63a68af3 100644 --- a/spec/models/bundle_context_spec.rb +++ b/spec/models/bundle_context_spec.rb @@ -126,9 +126,9 @@ it "expect the content of manifest rows" do expect(bc.manifest_rows).to eq( [ - {"druid"=>"druid:jy812bp9403", "sourceid"=>"bar-1.0", "object"=>"jy812bp9403", "label"=>"Label 1", "description"=>"This is a description for label 1"}, - {"druid"=>"druid:tz250tk7584", "sourceid"=>"bar-2.1", "object"=>"tz250tk7584", "label"=>"Label 2", "description"=>"This is a description for label 2"}, - {"druid"=>"druid:gn330dv6119", "sourceid"=>"bar-3.1", "object"=>"gn330dv6119", "label"=>"Label 3", "description"=>"This is a description for label 3"} + { "druid" => "druid:jy812bp9403", "sourceid" => "bar-1.0", "object" => "jy812bp9403", "label" => "Label 1", "description" => "This is a description for label 1" }, + { "druid" => "druid:tz250tk7584", "sourceid" => "bar-2.1", "object" => "tz250tk7584", "label" => "Label 2", "description" => "This is a description for label 2" }, + { "druid" => "druid:gn330dv6119", "sourceid" => "bar-3.1", "object" => "gn330dv6119", "label" => "Label 3", "description" => "This is a description for label 3" } ] ) end diff --git a/spec/services/discovery_report_spec.rb b/spec/services/discovery_report_spec.rb index d95165e4..f541aecc 100644 --- a/spec/services/discovery_report_spec.rb +++ b/spec/services/discovery_report_spec.rb @@ -69,7 +69,7 @@ end context "folders are not empty" do - let(:obj_file) { instance_double(PreAssembly::ObjectFile, path: "random/path", filesize: 324, mimetype: "")} + let(:obj_file) { instance_double(PreAssembly::ObjectFile, path: "random/path", filesize: 324, mimetype: "") } before do allow(dobj).to receive(:object_files).and_return([obj_file, obj_file]) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a2a44aec..844ae7fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,6 @@ require 'byebug' RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/views/job_runs/index.json.jbuilder_spec.rb b/spec/views/job_runs/index.json.jbuilder_spec.rb index 01676b76..db46e8c3 100644 --- a/spec/views/job_runs/index.json.jbuilder_spec.rb +++ b/spec/views/job_runs/index.json.jbuilder_spec.rb @@ -8,12 +8,12 @@ expect(json.class).to eq Array expect(json.size).to eq 2 expect(json[0]).to match a_hash_including( - 'job_type' => 'discovery_report', - 'output_location' => '/path/to/report' - ) - expect(json[1]).to match a_hash_including( - 'job_type' => 'discovery_report', - 'output_location' => '/path/to/report' - ) + 'job_type' => 'discovery_report', + 'output_location' => '/path/to/report' + ) + expect(json[1]).to match a_hash_including( + 'job_type' => 'discovery_report', + 'output_location' => '/path/to/report' + ) end end From 2300a7d4cd3c3705d5c992b42add8bb7a0d46e8c Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 15:26:08 -0700 Subject: [PATCH 2/8] rubocop --auto-correct --only=Lint --- app/lib/pre_assembly/digital_object.rb | 2 +- config/initializers/simple_form_bootstrap.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/pre_assembly/digital_object.rb b/app/lib/pre_assembly/digital_object.rb index 3ec89549..155c60e7 100644 --- a/app/lib/pre_assembly/digital_object.rb +++ b/app/lib/pre_assembly/digital_object.rb @@ -282,7 +282,7 @@ def content_md_file end def retry_handler(method_name, logger, params = {}) - Proc.new do |exception, attempt_number, total_delay| + Proc.new do |_exception, attempt_number, total_delay| log(" ** #{method_name} FAILED **; with params of #{params.inspect}; and trying attempt #{attempt_number} of #{Dor::Config.dor_services.num_attempts}; delayed #{total_delay} seconds") end end diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index 85c144ac..8a83e776 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -21,7 +21,7 @@ config.boolean_label_class = 'form-check-label' # How the label text should be generated altogether with the required text. - config.label_text = lambda { |label, required, explicit_label| "#{label} #{required}" } + config.label_text = lambda { |label, required, _explicit_label| "#{label} #{required}" } # Define the way to render check boxes / radio buttons with labels. config.boolean_style = :inline From 1af65efc81462449d8a1e771203af46f5ceeebd7 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 15:32:46 -0700 Subject: [PATCH 3/8] Manually fix remaning Lint errors --- app/lib/pre_assembly/bundle.rb | 10 --- app/lib/pre_assembly/smpl.rb | 115 ++++++++++++++++----------------- 2 files changed, 54 insertions(+), 71 deletions(-) diff --git a/app/lib/pre_assembly/bundle.rb b/app/lib/pre_assembly/bundle.rb index c2e56bec..8500a0bc 100644 --- a/app/lib/pre_assembly/bundle.rb +++ b/app/lib/pre_assembly/bundle.rb @@ -204,16 +204,6 @@ def process_digital_objects # Indicate that we finished. dobj.pre_assem_finished = true log "Completed #{dobj.druid}" - rescue Exception => e - # For now, just re-raise any exceptions. - # - # Later, we might decide to do the following: - # - catch specific types of expected exceptions - # - from that point, raise a PreAssembly::PreAssembleError - # - then catch such errors here, allowing the current - # digital object to fail but the remaining objects to be processed. - Honeybadger.notify(e) # ??? Isn't this what Honeybadger would do anyway w/o the rescue? - raise e ensure # Log the outcome no matter what. File.open(progress_log_file, 'a') { |f| f.puts log_progress_info(dobj).to_yaml } diff --git a/app/lib/pre_assembly/smpl.rb b/app/lib/pre_assembly/smpl.rb index 852a0bcc..ec6f0f57 100644 --- a/app/lib/pre_assembly/smpl.rb +++ b/app/lib/pre_assembly/smpl.rb @@ -72,70 +72,63 @@ def load_manifest end # load_manifest # actually generate content metadata for a specific druid in the manifest + # @return [String] XML def generate_cm(druid) - pid = druid.gsub!('druid:', '') - - if @manifest[druid] - current_directory = Dir.pwd - files = @manifest[druid][:files] - source_id = @manifest[druid][:source_id] - current_seq = '' - resources = {} - - # bundle the files into resources based on the sequence # defined in the manifest, a new sequence number triggers a new resource - files.each do |file| - seq = file[:sequence] - label = file[:label] || "" - resource_type = file[:resource_type] || @default_resource_type - if (!seq.nil? && seq != '' && seq != current_seq) # this is a new resource if we have a non-blank different sequence number - resources[seq.to_i] = { :label => label, :sequence => seq, :resource_type => resource_type, :files => [] } - current_seq = seq - end - resources[current_seq.to_i][:files] << file - resources[current_seq.to_i][:thumb] = file[:thumb] if file[:thumb] # any true/yes thumb attribute for any file in that resource triggers the whole resource as thumb=true + return '' unless @manifest[druid] + current_directory = Dir.pwd + files = @manifest[druid][:files] + current_seq = '' + resources = {} + + # bundle the files into resources based on the sequence # defined in the manifest, a new sequence number triggers a new resource + files.each do |file| + seq = file[:sequence] + label = file[:label] || '' + resource_type = file[:resource_type] || @default_resource_type + if (!seq.nil? && seq != '' && seq != current_seq) # this is a new resource if we have a non-blank different sequence number + resources[seq.to_i] = { :label => label, :sequence => seq, :resource_type => resource_type, :files => [] } + current_seq = seq end - - # generate the base of the XML file for this new druid - # generate content metadata - builder = Nokogiri::XML::Builder.new { |xml| - xml.contentMetadata(:objectId => druid, :type => @cm_type) { - resources.keys.sort.each do |seq| - resource = resources[seq] - resource_attributes = { :sequence => seq.to_s, :id => "#{druid}_#{seq}", :type => resource[:resource_type] } - resource_attributes[:thumb] = 'yes' if resource[:thumb] # add the thumb=yes attribute to the resource if it was marked that way in the manifest - xml.resource(resource_attributes) { - xml.label resource[:label] - - resource[:files].each do |file| - filename = file[:filename] || "" - role = file[:role] - file_attributes = @file_attributes[role.downcase] || @file_attributes['default'] - - publish = file[:publish] || file_attributes[:publish] || "true" - preserve = file[:preserve] || file_attributes[:preserve] || "true" - shelve = file[:shelve] || file_attributes[:shelve] || "true" - - # look for a checksum file named the same as this file - checksum = nil - FileUtils.cd(File.join(@bundle_dir, druid)) - md_files = Dir.glob("**/" + filename + ".md5") - checksum = get_checksum(File.join(@bundle_dir, druid, md_files[0])) if md_files.size == 1 # we found a corresponding md5 file, read it - - xml.file(:id => filename, :preserve => preserve, :publish => publish, :shelve => shelve) { - xml.checksum(checksum, :type => 'md5') if checksum && checksum != '' - } # end file - end # end loop over files - } # end resource - end # end loop over resources - } # end CM tag - } # end XML tag - - FileUtils.cd(current_directory) - - return builder.to_xml - else # no druid found in mainfest - return "" + resources[current_seq.to_i][:files] << file + resources[current_seq.to_i][:thumb] = file[:thumb] if file[:thumb] # any true/yes thumb attribute for any file in that resource triggers the whole resource as thumb=true end + + # generate the base of the XML file for this new druid + # generate content metadata + builder = Nokogiri::XML::Builder.new { |xml| + xml.contentMetadata(:objectId => druid, :type => @cm_type) { + resources.keys.sort.each do |seq| + resource = resources[seq] + resource_attributes = { :sequence => seq.to_s, :id => "#{druid}_#{seq}", :type => resource[:resource_type] } + resource_attributes[:thumb] = 'yes' if resource[:thumb] # add the thumb=yes attribute to the resource if it was marked that way in the manifest + xml.resource(resource_attributes) { + xml.label resource[:label] + + resource[:files].each do |file| + filename = file[:filename] || "" + role = file[:role] + file_attributes = @file_attributes[role.downcase] || @file_attributes['default'] + + publish = file[:publish] || file_attributes[:publish] || "true" + preserve = file[:preserve] || file_attributes[:preserve] || "true" + shelve = file[:shelve] || file_attributes[:shelve] || "true" + + # look for a checksum file named the same as this file + checksum = nil + FileUtils.cd(File.join(@bundle_dir, druid)) + md_files = Dir.glob("**/" + filename + ".md5") + checksum = get_checksum(File.join(@bundle_dir, druid, md_files[0])) if md_files.size == 1 # we found a corresponding md5 file, read it + + xml.file(:id => filename, :preserve => preserve, :publish => publish, :shelve => shelve) { + xml.checksum(checksum, :type => 'md5') if checksum && checksum != '' + } + end + } # end resource + end # end loop over resources + } # end CM tag + } # end XML tag + FileUtils.cd(current_directory) + builder.to_xml end def get_checksum(md5_file) From a60e38603050e78f344c25725e37951eb147e249 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 15:51:35 -0700 Subject: [PATCH 4/8] Further cleanup of Smpl.rb - accessors not needed, use readers instead - actually use the readers instead of instance vars in methods - remove `puts` statement and related `verbose` option - initialize `@manifest` in `#initialize` - some beautification --- app/lib/pre_assembly/smpl.rb | 58 ++++++++++++------------------ spec/lib/pre_assembly/smpl_spec.rb | 8 ++--- 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/app/lib/pre_assembly/smpl.rb b/app/lib/pre_assembly/smpl.rb index ec6f0f57..4730a39a 100644 --- a/app/lib/pre_assembly/smpl.rb +++ b/app/lib/pre_assembly/smpl.rb @@ -16,40 +16,30 @@ module PreAssembly class Smpl - include PreAssembly::Logging - - attr_accessor :manifest, :rows, :csv_filename, :bundle_dir, :default_resource_type, :cm_type + attr_reader :file_attributes, :manifest, :rows, :csv_filename, :bundle_dir def initialize(params) @bundle_dir = params[:bundle_dir] csv_file = params[:csv_filename] || 'smpl_manifest.csv' @csv_filename = File.join(@bundle_dir, csv_file) - @verbose = params[:verbose] || false # default publish/shelve/preserve attributes per "type" as defined in smpl filenames - @file_attributes = {} - @file_attributes['default'] = { :publish => 'no', :shelve => 'no', :preserve => 'yes' } - @file_attributes['pm'] = { :publish => 'no', :shelve => 'no', :preserve => 'yes' } - @file_attributes['sh'] = { :publish => 'no', :shelve => 'no', :preserve => 'yes' } - @file_attributes['sl'] = { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } - @file_attributes['images'] = { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } - @file_attributes['transcript'] = { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } - - @default_resource_type = "media" - @cm_type = "media" - + @file_attributes = { + 'default' => { :publish => 'no', :shelve => 'no', :preserve => 'yes' }, + 'pm' => { :publish => 'no', :shelve => 'no', :preserve => 'yes' }, + 'sh' => { :publish => 'no', :shelve => 'no', :preserve => 'yes' }, + 'sl' => { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' }, + 'images' => { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' }, + 'transcript' => { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } + } + @manifest = {} # read CSV load_manifest # this will cache the entire manifest in @rows and @manifest - - puts "found #{@rows.size} rows in manifest" if @verbose end def load_manifest # load file into @rows and then build up @manifest @rows = CsvImporter.parse_to_hash(@csv_filename) - - @manifest = {} - @rows.each do |row| druid = get_druid(row[:filename]) role = get_role(row[:filename]) @@ -65,18 +55,18 @@ def load_manifest shelve = defined?(row[:shelve]) ? row[:shelve] || nil : nil preserve = defined?(row[:preserve]) ? row[:preserve] || nil : nil - @manifest[druid] = { :source_id => '', :files => [] } if manifest[druid].nil? - @manifest[druid][:source_id] = row[:source_id] if (defined?(row[:source_id]) && row[:source_id]) - @manifest[druid][:files] << { :thumb => thumb, :publish => publish, :shelve => shelve, :preserve => preserve, :resource_type => resource_type, :role => role, :file_extention => file_extension, :filename => row[:filename], :label => row[:label], :sequence => row[:sequence] } + manifest[druid] = { :source_id => '', :files => [] } if manifest[druid].nil? + manifest[druid][:source_id] = row[:source_id] if (defined?(row[:source_id]) && row[:source_id]) + manifest[druid][:files] << { :thumb => thumb, :publish => publish, :shelve => shelve, :preserve => preserve, :resource_type => resource_type, :role => role, :file_extention => file_extension, :filename => row[:filename], :label => row[:label], :sequence => row[:sequence] } end # loop over all rows end # load_manifest # actually generate content metadata for a specific druid in the manifest # @return [String] XML def generate_cm(druid) - return '' unless @manifest[druid] + return '' unless manifest[druid] current_directory = Dir.pwd - files = @manifest[druid][:files] + files = manifest[druid][:files] current_seq = '' resources = {} @@ -84,7 +74,7 @@ def generate_cm(druid) files.each do |file| seq = file[:sequence] label = file[:label] || '' - resource_type = file[:resource_type] || @default_resource_type + resource_type = file[:resource_type] || 'media' if (!seq.nil? && seq != '' && seq != current_seq) # this is a new resource if we have a non-blank different sequence number resources[seq.to_i] = { :label => label, :sequence => seq, :resource_type => resource_type, :files => [] } current_seq = seq @@ -96,7 +86,7 @@ def generate_cm(druid) # generate the base of the XML file for this new druid # generate content metadata builder = Nokogiri::XML::Builder.new { |xml| - xml.contentMetadata(:objectId => druid, :type => @cm_type) { + xml.contentMetadata(:objectId => druid, :type => 'media') { resources.keys.sort.each do |seq| resource = resources[seq] resource_attributes = { :sequence => seq.to_s, :id => "#{druid}_#{seq}", :type => resource[:resource_type] } @@ -106,18 +96,16 @@ def generate_cm(druid) resource[:files].each do |file| filename = file[:filename] || "" - role = file[:role] - file_attributes = @file_attributes[role.downcase] || @file_attributes['default'] - - publish = file[:publish] || file_attributes[:publish] || "true" - preserve = file[:preserve] || file_attributes[:preserve] || "true" - shelve = file[:shelve] || file_attributes[:shelve] || "true" + attrs = file_attributes[file[:role].downcase] || file_attributes['default'] + publish = file[:publish] || attrs[:publish] || "true" + preserve = file[:preserve] || attrs[:preserve] || "true" + shelve = file[:shelve] || attrs[:shelve] || "true" # look for a checksum file named the same as this file checksum = nil - FileUtils.cd(File.join(@bundle_dir, druid)) + FileUtils.cd(File.join(bundle_dir, druid)) md_files = Dir.glob("**/" + filename + ".md5") - checksum = get_checksum(File.join(@bundle_dir, druid, md_files[0])) if md_files.size == 1 # we found a corresponding md5 file, read it + checksum = get_checksum(File.join(bundle_dir, druid, md_files[0])) if md_files.size == 1 # we found a corresponding md5 file, read it xml.file(:id => filename, :preserve => preserve, :publish => publish, :shelve => shelve) { xml.checksum(checksum, :type => 'md5') if checksum && checksum != '' diff --git a/spec/lib/pre_assembly/smpl_spec.rb b/spec/lib/pre_assembly/smpl_spec.rb index 202468c0..f449fc6e 100644 --- a/spec/lib/pre_assembly/smpl_spec.rb +++ b/spec/lib/pre_assembly/smpl_spec.rb @@ -14,7 +14,7 @@ let(:dobj1) { setup_dobj('aa111aa1111', smpl_manifest) } let(:dobj2) { setup_dobj('bb222bb2222', smpl_manifest) } let(:smpl_manifest) do - described_class.new(:csv_filename => 'smpl_manifest.csv', :bundle_dir => bundle_dir, :verbose => false) + described_class.new(:csv_filename => 'smpl_manifest.csv', :bundle_dir => bundle_dir) end it "generates technicalMetadata for SMPL by combining all existing _techmd.xml files" do @@ -38,7 +38,7 @@ describe '#create_content_metadata - with thumb declaration' do it "generates content metadata from a SMPL manifest with a thumb column set to yes" do - smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_with_thumb.csv', :bundle_dir => bundle_dir, :verbose => false) + smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_with_thumb.csv', :bundle_dir => bundle_dir) dobj1 = setup_dobj('aa111aa1111', smpl_manifest) dobj2 = setup_dobj('bb222bb2222', smpl_manifest) dobj1.create_content_metadata @@ -48,7 +48,7 @@ end it "generates content metadata from a SMPL manifest with a thumb column set to true" do - smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_with_thumb_true.csv', :bundle_dir => bundle_dir, :verbose => false) + smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_with_thumb_true.csv', :bundle_dir => bundle_dir) dobj1 = setup_dobj('aa111aa1111', smpl_manifest) dobj2 = setup_dobj('bb222bb2222', smpl_manifest) dobj1.create_content_metadata @@ -58,7 +58,7 @@ end it "generates content metadata from a SMPL manifest with no thumbs when the thumb column is set to no" do - smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_thumb_no.csv', :bundle_dir => bundle_dir, :verbose => false) + smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_thumb_no.csv', :bundle_dir => bundle_dir) dobj1 = setup_dobj('aa111aa1111', smpl_manifest) dobj2 = setup_dobj('bb222bb2222', smpl_manifest) dobj1.create_content_metadata From 8008fa3754b8b788c51c505b29e6278058241c9b Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 16:05:51 -0700 Subject: [PATCH 5/8] Apply *most* Rubocop style auto-corrections Excludes `StringLiterals` and `HashSyntax` as high churn for now. --- .rubocop.yml | 6 ++++ app/lib/pre_assembly/bundle.rb | 20 ++++++------- app/lib/pre_assembly/digital_object.rb | 10 +++---- app/lib/pre_assembly/logging.rb | 10 +++---- app/lib/pre_assembly/smpl.rb | 28 +++++++++---------- app/models/bundle_context.rb | 2 +- app/services/discovery_report.rb | 4 +-- config/deploy.rb | 5 ++-- config/deploy/old_prod.rb | 2 +- config/deploy/old_stage.rb | 2 +- config/deploy/prod.rb | 2 +- config/deploy/stage.rb | 2 +- config/initializers/simple_form_bootstrap.rb | 2 +- .../bundle_contexts_controller_spec.rb | 10 +++---- spec/controllers/job_runs_controller_spec.rb | 2 +- spec/lib/csv_importer_spec.rb | 2 +- spec/lib/pre_assembly/bundle_spec.rb | 20 ++++++------- spec/lib/pre_assembly/digital_object_spec.rb | 14 +++++----- spec/lib/pre_assembly/smpl_spec.rb | 2 +- spec/models/bundle_context_spec.rb | 6 ++-- spec/services/discovery_report_spec.rb | 2 +- 21 files changed, 75 insertions(+), 78 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index da5f671b..c391c860 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -48,3 +48,9 @@ Style/FrozenStringLiteralComment: Style/NumericPredicate: # "> 0" is not less readable than ".positive?" Enabled: false + +Style/RegexpLiteral: + Enabled: false + +Style/SymbolArray: + MinSize: 4 diff --git a/app/lib/pre_assembly/bundle.rb b/app/lib/pre_assembly/bundle.rb index 8500a0bc..aff95af8 100644 --- a/app/lib/pre_assembly/bundle.rb +++ b/app/lib/pre_assembly/bundle.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module PreAssembly class Bundle include PreAssembly::Logging @@ -30,9 +28,7 @@ class Bundle def initialize(bundle_context) @bundle_context = bundle_context - if bundle_context.smpl_cm_style? - self.smpl_manifest = PreAssembly::Smpl.new(:csv_filename => bundle_context.smpl_manifest, :bundle_dir => bundle_dir) - end + self.smpl_manifest = PreAssembly::Smpl.new(:csv_filename => bundle_context.smpl_manifest, :bundle_dir => bundle_dir) if bundle_context.smpl_cm_style? self.skippables = {} load_skippables end @@ -63,7 +59,7 @@ def run_log_msg :project_name => project_name, :bundle_dir => bundle_dir, :assembly_staging_dir => Settings.assembly_staging_dir, - :environment => ENV['RAILS_ENV'], + :environment => ENV['RAILS_ENV'] } log_params.map { |k, v| "#{k}=#{v.inspect}" }.join(', ') end @@ -106,7 +102,7 @@ def digital_objects # manifest columns. The column name to use is configured by the # user invoking the pre-assembly script. def discover_containers_via_manifest - raise RuntimeError, ':manifest_cols must be specified' unless manifest_cols + raise ':manifest_cols must be specified' unless manifest_cols # TODO: note that manifest_cols is a constant in bundle_context obj_sym = manifest_cols[:object_container].to_sym manifest_rows.each_with_index { |r, i| raise "Missing #{obj_sym} in row #{i}: #{r}" unless r[obj_sym] } @@ -136,7 +132,7 @@ def discover_object_files(stageable_items) object_files = [] Array(stageable_items).each do |stageable| find_files_recursively(stageable).each do |file_path| - object_files.push(new_object_file stageable, file_path) + object_files.push(new_object_file(stageable, file_path)) end end object_files @@ -145,7 +141,7 @@ def discover_object_files(stageable_items) # A convenience method to return all ObjectFiles for all digital objects. # Also used for stubbing during testing. def all_object_files - digital_objects.map { |dobj| dobj.object_files }.flatten + digital_objects.map(&:object_files).flatten end def new_object_file(stageable, file_path) @@ -195,7 +191,7 @@ def process_digital_objects log "#{total_obj - n} remaining in run | #{total_obj} running" log " - Processing object: #{dobj.container}" log " - N object files: #{dobj.object_files.size}" - num_no_file_warnings += 1 if dobj.object_files.size == 0 + num_no_file_warnings += 1 if dobj.object_files.empty? begin # Try to pre_assemble the digital object. @@ -214,12 +210,12 @@ def process_digital_objects total_time_remaining = (avg_time_per_object * (total_obj - next_n)).floor end - log "**WARNING**: #{num_no_file_warnings} objects had no files" if (num_no_file_warnings > 0) + log "**WARNING**: #{num_no_file_warnings} objects had no files" if num_no_file_warnings > 0 log "#{total_obj} objects pre-assembled" end def objects_to_process - @o2p ||= digital_objects.reject { |dobj| skippables.has_key?(dobj.container) } + @o2p ||= digital_objects.reject { |dobj| skippables.key?(dobj.container) } end def log_progress_info(dobj) diff --git a/app/lib/pre_assembly/digital_object.rb b/app/lib/pre_assembly/digital_object.rb index 155c60e7..2b477df2 100644 --- a/app/lib/pre_assembly/digital_object.rb +++ b/app/lib/pre_assembly/digital_object.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module PreAssembly class DigitalObject include PreAssembly::Logging @@ -233,12 +231,12 @@ def write_content_metadata # Object files that should be included in content metadata. def content_object_files - object_files.reject { |ofile| ofile.exclude_from_content }.sort + object_files.reject(&:exclude_from_content).sort end # Checks filesystem for expected files def object_files_exist? - return false if object_files.size == 0 + return false if object_files.empty? object_files.map(&:path).all? { |path| File.readable?(path) } end @@ -262,7 +260,7 @@ def initialize_assembly_workflow with_retries(max_tries: Dor::Config.dor_services.num_attempts, rescue: Exception, handler: retry_handler('INITIALIZE_ASSEMBLY_WORKFLOW', method(:log))) do RestClient.post(assembly_workflow_url, {}).tap do |result| next if result && (200..204).include?(result.code) - raise RuntimeError, "POST #{assembly_workflow_url} returned #{result.code}" + raise "POST #{assembly_workflow_url} returned #{result.code}" end end end @@ -282,7 +280,7 @@ def content_md_file end def retry_handler(method_name, logger, params = {}) - Proc.new do |_exception, attempt_number, total_delay| + proc do |_exception, attempt_number, total_delay| log(" ** #{method_name} FAILED **; with params of #{params.inspect}; and trying attempt #{attempt_number} of #{Dor::Config.dor_services.num_attempts}; delayed #{total_delay} seconds") end end diff --git a/app/lib/pre_assembly/logging.rb b/app/lib/pre_assembly/logging.rb index 1434e41e..5710de21 100644 --- a/app/lib/pre_assembly/logging.rb +++ b/app/lib/pre_assembly/logging.rb @@ -5,17 +5,17 @@ module Logging :error => Logger::ERROR, :warn => Logger::WARN, :info => Logger::INFO, - :debug => Logger::DEBUG, - } + :debug => Logger::DEBUG + }.freeze - LOG_FORMAT = "%-6s -- %s -- %s\n" - TIME_FORMAT = "%Y-%m-%d %H:%M:%S" + LOG_FORMAT = "%-6s -- %s -- %s\n".freeze + TIME_FORMAT = "%Y-%m-%d %H:%M:%S".freeze @@log ||= Logger.new(File.join(Rails.root, 'log', "#{Rails.env}.log")) @@log.level = LEVELS[:info] @@log.formatter = proc do |severity, datetime, _progname, msg| - LOG_FORMAT % [severity, datetime.strftime(TIME_FORMAT), msg] + format(LOG_FORMAT, severity, datetime.strftime(TIME_FORMAT), msg) end def log(msg, severity = :info) diff --git a/app/lib/pre_assembly/smpl.rb b/app/lib/pre_assembly/smpl.rb index 4730a39a..2bb4fca7 100644 --- a/app/lib/pre_assembly/smpl.rb +++ b/app/lib/pre_assembly/smpl.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - # This class generates contentMetadata from a SMPL supplied manifest # see the "SMPL Content" section here for a description of the manifest: # https://consul.stanford.edu/pages/viewpage.action?pageId=136365158#AutomatedAccessioningandObjectRemediation(pre-assemblyandassembly)-SMPLContent @@ -48,7 +46,7 @@ def load_manifest resource_type = defined?(row[:resource_type]) ? row[:resource_type] || nil : nil # set the thumb attribute for this resource if it is set in the manifest to true, yes or thumb (set to false if no value or column is missing) - thumb = (defined?(row[:thumb]) && row[:thumb] && ['true', 'yes', 'thumb'].include?(row[:thumb].downcase)) ? true : false + thumb = defined?(row[:thumb]) && row[:thumb] && %w[true yes thumb].include?(row[:thumb].downcase) ? true : false # set the publish/preserve/shelve if available, otherwise we'll use the defaults publish = defined?(row[:publish]) ? row[:publish] || nil : nil @@ -56,7 +54,7 @@ def load_manifest preserve = defined?(row[:preserve]) ? row[:preserve] || nil : nil manifest[druid] = { :source_id => '', :files => [] } if manifest[druid].nil? - manifest[druid][:source_id] = row[:source_id] if (defined?(row[:source_id]) && row[:source_id]) + manifest[druid][:source_id] = row[:source_id] if defined?(row[:source_id]) && row[:source_id] manifest[druid][:files] << { :thumb => thumb, :publish => publish, :shelve => shelve, :preserve => preserve, :resource_type => resource_type, :role => role, :file_extention => file_extension, :filename => row[:filename], :label => row[:label], :sequence => row[:sequence] } end # loop over all rows end # load_manifest @@ -75,7 +73,7 @@ def generate_cm(druid) seq = file[:sequence] label = file[:label] || '' resource_type = file[:resource_type] || 'media' - if (!seq.nil? && seq != '' && seq != current_seq) # this is a new resource if we have a non-blank different sequence number + if !seq.nil? && seq != '' && seq != current_seq # this is a new resource if we have a non-blank different sequence number resources[seq.to_i] = { :label => label, :sequence => seq, :resource_type => resource_type, :files => [] } current_seq = seq end @@ -85,13 +83,13 @@ def generate_cm(druid) # generate the base of the XML file for this new druid # generate content metadata - builder = Nokogiri::XML::Builder.new { |xml| - xml.contentMetadata(:objectId => druid, :type => 'media') { + builder = Nokogiri::XML::Builder.new do |xml| + xml.contentMetadata(:objectId => druid, :type => 'media') do resources.keys.sort.each do |seq| resource = resources[seq] resource_attributes = { :sequence => seq.to_s, :id => "#{druid}_#{seq}", :type => resource[:resource_type] } resource_attributes[:thumb] = 'yes' if resource[:thumb] # add the thumb=yes attribute to the resource if it was marked that way in the manifest - xml.resource(resource_attributes) { + xml.resource(resource_attributes) do xml.label resource[:label] resource[:files].each do |file| @@ -107,14 +105,14 @@ def generate_cm(druid) md_files = Dir.glob("**/" + filename + ".md5") checksum = get_checksum(File.join(bundle_dir, druid, md_files[0])) if md_files.size == 1 # we found a corresponding md5 file, read it - xml.file(:id => filename, :preserve => preserve, :publish => publish, :shelve => shelve) { + xml.file(:id => filename, :preserve => preserve, :publish => publish, :shelve => shelve) do xml.checksum(checksum, :type => 'md5') if checksum && checksum != '' - } + end end - } # end resource + end # end resource end # end loop over resources - } # end CM tag - } # end XML tag + end # end CM tag + end # end XML tag FileUtils.cd(current_directory) builder.to_xml end @@ -127,7 +125,7 @@ def get_checksum(md5_file) def get_role(filename) matches = filename.scan(/_pm|_sl|_sh/) - if matches.size == 0 + if matches.empty? return 'Images' if ['.tif', '.tiff', '.jpg', '.jpeg', '.jp2'].include? File.extname(filename).downcase return 'Transcript' if ['.pdf', '.txt', '.doc'].include? File.extname(filename).downcase return '' @@ -138,7 +136,7 @@ def get_role(filename) def get_druid(filename) matches = filename.scan(/[0-9a-zA-Z]{11}/) - return '' if matches.size == 0 + return '' if matches.empty? matches.first.strip end end diff --git a/app/models/bundle_context.rb b/app/models/bundle_context.rb index 6d4250fc..b85bad39 100644 --- a/app/models/bundle_context.rb +++ b/app/models/bundle_context.rb @@ -105,7 +105,7 @@ def default_enums end def normalize_dir(dir) - dir.chomp('/') if dir + dir&.chomp('/') end def normalize_bundle_dir diff --git a/app/services/discovery_report.rb b/app/services/discovery_report.rb index 423cecad..3b629c8c 100644 --- a/app/services/discovery_report.rb +++ b/app/services/discovery_report.rb @@ -41,7 +41,7 @@ def process_dobj(dobj) counts = { total_size: dobj.object_files.map(&:filesize).sum, mimetypes: Hash.new(0), - filename_no_extension: filename_no_extension.count, + filename_no_extension: filename_no_extension.count } dobj.object_files.each { |obj| counts[:mimetypes][obj.mimetype] += 1 } # number of files by mimetype empty_files = dobj.object_files.count { |obj| obj.filesize == 0 } @@ -79,7 +79,7 @@ def registration_check(druid) return { apo_not_registered: true } end rescue RuntimeError # HTTP timeout, network error, whatever - return { dor_connection_error: true } + { dor_connection_error: true } end # For use by template diff --git a/config/deploy.rb b/config/deploy.rb index d4da5d7b..5dedc7eb 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,11 +1,10 @@ set :application, 'pre-assembly' set :repo_url, 'ssh://git@github.com/sul-dlss/pre-assembly' -set :ssh_options, { +set :ssh_options, keys: [Capistrano::OneTimeKey.temporary_ssh_private_key_path], forward_agent: true, - auth_methods: %w(publickey password) -} + auth_methods: %w[publickey password] # Default branch is :master ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call diff --git a/config/deploy/old_prod.rb b/config/deploy/old_prod.rb index 6a40ca13..7add6fc9 100644 --- a/config/deploy/old_prod.rb +++ b/config/deploy/old_prod.rb @@ -1,4 +1,4 @@ -server 'sul-lyberservices-prod.stanford.edu', user: 'lyberadmin', roles: %w{web app db} +server 'sul-lyberservices-prod.stanford.edu', user: 'lyberadmin', roles: %w[web app db] set :repo_url, 'https://github.com/sul-dlss/pre-assembly.git' Capistrano::OneTimeKey.generate_one_time_key! diff --git a/config/deploy/old_stage.rb b/config/deploy/old_stage.rb index ff7c2696..184ac6b7 100644 --- a/config/deploy/old_stage.rb +++ b/config/deploy/old_stage.rb @@ -1,4 +1,4 @@ -server 'sul-lyberservices-test.stanford.edu', user: 'lyberadmin', roles: %w{web app db} +server 'sul-lyberservices-test.stanford.edu', user: 'lyberadmin', roles: %w[web app db] set :repo_url, 'https://github.com/sul-dlss/pre-assembly.git' Capistrano::OneTimeKey.generate_one_time_key! diff --git a/config/deploy/prod.rb b/config/deploy/prod.rb index 9a2c469b..107c3afe 100644 --- a/config/deploy/prod.rb +++ b/config/deploy/prod.rb @@ -1,4 +1,4 @@ -server 'sul-preassembly-prod.stanford.edu', user: 'preassembly', roles: %w{web app db} +server 'sul-preassembly-prod.stanford.edu', user: 'preassembly', roles: %w[web app db] Capistrano::OneTimeKey.generate_one_time_key! set :rails_env, 'production' diff --git a/config/deploy/stage.rb b/config/deploy/stage.rb index 06f93742..cc7cb9e6 100644 --- a/config/deploy/stage.rb +++ b/config/deploy/stage.rb @@ -1,4 +1,4 @@ -server 'sul-preassembly-stage.stanford.edu', user: 'preassembly', roles: %w{web app db} +server 'sul-preassembly-stage.stanford.edu', user: 'preassembly', roles: %w[web app db] Capistrano::OneTimeKey.generate_one_time_key! set :rails_env, 'production' diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index 8a83e776..e7a82b3d 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -21,7 +21,7 @@ config.boolean_label_class = 'form-check-label' # How the label text should be generated altogether with the required text. - config.label_text = lambda { |label, required, _explicit_label| "#{label} #{required}" } + config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" } # Define the way to render check boxes / radio buttons with labels. config.boolean_style = :inline diff --git a/spec/controllers/bundle_contexts_controller_spec.rb b/spec/controllers/bundle_contexts_controller_spec.rb index 0a713a99..ac302bfd 100644 --- a/spec/controllers/bundle_contexts_controller_spec.rb +++ b/spec/controllers/bundle_contexts_controller_spec.rb @@ -20,7 +20,7 @@ end context 'users persisted in db' do - before { sign_in(create :user) } + before { sign_in(create(:user)) } it "should have current_user" do expect(subject.current_user).not_to be_nil @@ -70,20 +70,20 @@ it 'do not create objects' do params[:bundle_context].merge!(project_name: nil) expect { post :create, params: params }.not_to change(BundleContext, :count) - expect { + expect do post :create, params: { bundle_context: { project_name: '', content_structure: '', content_metadata_creation: '', bundle_dir: '' - } }}.not_to change(BundleContext, :count) - expect { + } } end.not_to change(BundleContext, :count) + expect do post :create, params: { bundle_context: { project_name: "SMPL's folly", content_structure: '', content_metadata_creation: '', bundle_dir: '' - } }}.not_to change(BundleContext, :count) + } } end.not_to change(BundleContext, :count) end end end diff --git a/spec/controllers/job_runs_controller_spec.rb b/spec/controllers/job_runs_controller_spec.rb index 399f1269..6aacccbf 100644 --- a/spec/controllers/job_runs_controller_spec.rb +++ b/spec/controllers/job_runs_controller_spec.rb @@ -1,5 +1,5 @@ RSpec.describe JobRunsController, type: :controller do - before { sign_in(create :user) } + before { sign_in(create(:user)) } describe 'GET #show' do it 'returns http success' do diff --git a/spec/lib/csv_importer_spec.rb b/spec/lib/csv_importer_spec.rb index 4a33cd87..07540fe3 100644 --- a/spec/lib/csv_importer_spec.rb +++ b/spec/lib/csv_importer_spec.rb @@ -7,7 +7,7 @@ it "loads a CSV as a hash with indifferent access" do expect(manifest).to be_an(Array) expect(manifest.size).to eq(3) - headers = %w{format sourceid object label year inst_notes prod_notes has_more_metadata description} + headers = %w[format sourceid object label year inst_notes prod_notes has_more_metadata description] expect(manifest).to all(be_an(ActiveSupport::HashWithIndifferentAccess)) # accessible w/ string and symbols expect(manifest).to all(include(*headers)) expect(manifest[0][:description]).to be_nil diff --git a/spec/lib/pre_assembly/bundle_spec.rb b/spec/lib/pre_assembly/bundle_spec.rb index d77abe52..7433063f 100644 --- a/spec/lib/pre_assembly/bundle_spec.rb +++ b/spec/lib/pre_assembly/bundle_spec.rb @@ -17,9 +17,9 @@ bc.save b = PreAssembly::Bundle.new bc pids = [] - expect { + expect do pids = b.run_pre_assembly - }.not_to raise_error + end.not_to raise_error expect(pids).to eq ["druid:jy812bp9403", "druid:tz250tk7584", "druid:gn330dv6119"] end end @@ -29,7 +29,7 @@ allow(smpl_multimedia).to receive(:progress_log_file).and_return('spec/test_data/input/mock_progress_log.yaml') expect(smpl_multimedia.skippables).to eq({}) smpl_multimedia.load_skippables - expect(smpl_multimedia.skippables).to eq({ "aa" => true, "bb" => true }) + expect(smpl_multimedia.skippables).to eq("aa" => true, "bb" => true) end end @@ -60,7 +60,7 @@ describe '#object_discovery: discovery via manifest and crawl' do it "discover_containers_via_manifest() should return expected information" do - vals = %w(123.tif 456.tif 789.tif) + vals = %w[123.tif 456.tif 789.tif] flat_dir_images.manifest_cols[:object_container] = :col_foo allow(flat_dir_images).to receive(:manifest_rows).and_return(vals.map { |v| { object: v } }) expect(flat_dir_images.discover_containers_via_manifest).to eq(vals.map { |v| flat_dir_images.path_in_bundle v }) @@ -75,7 +75,7 @@ describe 'object discovery: #discover_object_files' do let(:fs) do - %w( + %w[ gn330dv6119/image1.jp2 gn330dv6119/image1.tif gn330dv6119/image2.jp2 @@ -85,10 +85,10 @@ jy812bp9403/05/image1.jp2 tz250tk7584/00/image1.tif tz250tk7584/00/image2.tif - ) + ] end let(:files) { fs.map { |f| images_jp2_tif.path_in_bundle f } } - let(:dirs) { %w(gn330dv6119 jy812bp9403 tz250tk7584).map { |d| images_jp2_tif.path_in_bundle d } } + let(:dirs) { %w[gn330dv6119 jy812bp9403 tz250tk7584].map { |d| images_jp2_tif.path_in_bundle d } } it "finds expected files with correct relative paths" do tests = [ @@ -143,7 +143,7 @@ # - within a subdir of bundle dir, with file deeper { :stageable => 'BUNDLE/a/b', :file_path => 'BUNDLE/a/b/c/d/x.tif', - :exp_rel_path => 'b/c/d/x.tif' }, + :exp_rel_path => 'b/c/d/x.tif' } ] tests.each do |t| ofile = flat_dir_images.new_object_file t[:stageable], t[:file_path] @@ -232,7 +232,7 @@ it "#dir_glob returns expected information" do exp = [1, 2, 3].map { |n| flat_dir_images.path_in_bundle "image#{n}.tif" } - expect(flat_dir_images.dir_glob(flat_dir_images.path_in_bundle "*.tif")).to eq(exp) + expect(flat_dir_images.dir_glob(flat_dir_images.path_in_bundle("*.tif"))).to eq(exp) end it "#find_files_recursively returns expected information" do @@ -256,7 +256,7 @@ "manifest.csv", "tz250tk7584/00/image1.tif", "tz250tk7584/00/image2.tif" - ], + ] }.each do |proj, files| b = described_class.new(bundle_context_from_hash(proj)) exp_files = files.map { |f| b.path_in_bundle f } diff --git a/spec/lib/pre_assembly/digital_object_spec.rb b/spec/lib/pre_assembly/digital_object_spec.rb index bc0f84f9..8835d7c7 100644 --- a/spec/lib/pre_assembly/digital_object_spec.rb +++ b/spec/lib/pre_assembly/digital_object_spec.rb @@ -19,7 +19,7 @@ def add_object_files(extension = 'tif') :path => "#{dobj.bundle_dir}/#{dru}/#{f}", :relative_path => f, :exclude_from_content => false, - :checksum => "#{i}" * 4 + :checksum => i.to_s * 4 ) end end @@ -116,7 +116,7 @@ def add_object_files(extension = 'tif') it "content_object_files() should filter @object_files correctly" do # Generate some object_files. - files = %w(file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif) + files = %w[file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif] n = files.size m = n / 2 dobj.object_files = files.map do |f| @@ -129,7 +129,7 @@ def add_object_files(extension = 'tif') ofiles = dobj.content_object_files expect(ofiles.size).to eq(m) # Also check their ordering. - expect(ofiles.map { |f| f.relative_path }).to eq(files[m..-1].sort) + expect(ofiles.map(&:relative_path)).to eq(files[m..-1].sort) end it "generates the expected xml text" do @@ -142,7 +142,7 @@ def add_object_files(extension = 'tif') file_name = File.join(tmp_area, 'metadata', dobj.send(:content_md_file)) expect(File.exist?(file_name)).to eq(false) dobj.write_content_metadata - expect(noko_doc(File.read file_name)).to be_equivalent_to exp_xml + expect(noko_doc(File.read(file_name))).to be_equivalent_to exp_xml end end end @@ -240,7 +240,7 @@ def add_object_files(extension = 'tif') it "content_object_files() should filter @object_files correctly" do # Generate some object_files. - files = %w(file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif) + files = %w[file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif] n = files.size m = n / 2 dobj.object_files = files.map do |f| @@ -253,7 +253,7 @@ def add_object_files(extension = 'tif') ofiles = dobj.content_object_files expect(ofiles.size).to eq(m) # Also check their ordering. - expect(ofiles.map { |f| f.relative_path }).to eq(files[m..-1].sort) + expect(ofiles.map(&:relative_path)).to eq(files[m..-1].sort) end it "generates the expected xml text" do @@ -305,7 +305,7 @@ def add_object_files(extension = 'tif') it "content_object_files() should filter @object_files correctly" do # Generate some object_files. - files = %w(file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif) + files = %w[file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif] dobj.object_files = files.map do |f| PreAssembly::ObjectFile.new(:exclude_from_content => false, :relative_path => f) end diff --git a/spec/lib/pre_assembly/smpl_spec.rb b/spec/lib/pre_assembly/smpl_spec.rb index f449fc6e..23896bd7 100644 --- a/spec/lib/pre_assembly/smpl_spec.rb +++ b/spec/lib/pre_assembly/smpl_spec.rb @@ -25,7 +25,7 @@ counts = exp_xml.css('Count') expect(counts.size).to eq(4) # four nodes that have file info # look for some specific bits in the files that have been assembled - expect(counts.map(&:content)).to eq(['279', '217', '280', '218']) + expect(counts.map(&:content)).to eq(%w[279 217 280 218]) end it "generates content metadata from a SMPL manifest with no thumb columns" do diff --git a/spec/models/bundle_context_spec.rb b/spec/models/bundle_context_spec.rb index 63a68af3..420174bb 100644 --- a/spec/models/bundle_context_spec.rb +++ b/spec/models/bundle_context_spec.rb @@ -1,10 +1,10 @@ RSpec.describe BundleContext, type: :model do - let(:attr_hash) { + let(:attr_hash) do { project_name: 'Images_jp2_tif', - bundle_dir: 'spec/test_data/images_jp2_tif', + bundle_dir: 'spec/test_data/images_jp2_tif' } - } + end subject(:bc) { build(:bundle_context_with_deleted_output_dir, attr_hash) } context "validation" do diff --git a/spec/services/discovery_report_spec.rb b/spec/services/discovery_report_spec.rb index f541aecc..96eda2ef 100644 --- a/spec/services/discovery_report_spec.rb +++ b/spec/services/discovery_report_spec.rb @@ -108,7 +108,7 @@ druid: "druid:kk203bw3276", errors: { dupes: true }, counts: { - total_size: 254802, + total_size: 254_802, mimetypes: { 'image/tiff' => 4, 'image/jp2' => 2 }, filename_no_extension: 0 } From c0b157f1abb44035efd9c338bd800bd0297f2674 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 16:11:53 -0700 Subject: [PATCH 6/8] Reapply Layout and *Security* auto-corrections --- config/deploy.rb | 8 ++++---- spec/controllers/bundle_contexts_controller_spec.rb | 6 ++++-- spec/support/bundle_setup.rb | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 5dedc7eb..8bb7fadb 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,10 +1,10 @@ set :application, 'pre-assembly' set :repo_url, 'ssh://git@github.com/sul-dlss/pre-assembly' -set :ssh_options, - keys: [Capistrano::OneTimeKey.temporary_ssh_private_key_path], - forward_agent: true, - auth_methods: %w[publickey password] +set :ssh_options, + keys: [Capistrano::OneTimeKey.temporary_ssh_private_key_path], + forward_agent: true, + auth_methods: %w[publickey password] # Default branch is :master ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call diff --git a/spec/controllers/bundle_contexts_controller_spec.rb b/spec/controllers/bundle_contexts_controller_spec.rb index ac302bfd..8f50f172 100644 --- a/spec/controllers/bundle_contexts_controller_spec.rb +++ b/spec/controllers/bundle_contexts_controller_spec.rb @@ -76,14 +76,16 @@ content_structure: '', content_metadata_creation: '', bundle_dir: '' - } } end.not_to change(BundleContext, :count) + } } + end .not_to change(BundleContext, :count) expect do post :create, params: { bundle_context: { project_name: "SMPL's folly", content_structure: '', content_metadata_creation: '', bundle_dir: '' - } } end.not_to change(BundleContext, :count) + } } + end .not_to change(BundleContext, :count) end end end diff --git a/spec/support/bundle_setup.rb b/spec/support/bundle_setup.rb index b4a1e172..72c2b8ad 100644 --- a/spec/support/bundle_setup.rb +++ b/spec/support/bundle_setup.rb @@ -5,7 +5,7 @@ def bundle_setup(proj) def hash_from_proj(proj) filename = "spec/test_data/project_config_files/#{proj}.yaml" - YAML.load(File.read(filename)).merge('config_filename' => filename) + YAML.safe_load(File.read(filename)).merge('config_filename' => filename) end def noko_doc(x) From e3e695918e235a92a0ac7ae522de24fcd52e6121 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 16:13:55 -0700 Subject: [PATCH 7/8] Apply rubocop Performance auto-corrections --- app/lib/pre_assembly/bundle.rb | 2 +- app/lib/pre_assembly/digital_object.rb | 2 +- spec/controllers/bundle_contexts_controller_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/lib/pre_assembly/bundle.rb b/app/lib/pre_assembly/bundle.rb index aff95af8..f4a82a4f 100644 --- a/app/lib/pre_assembly/bundle.rb +++ b/app/lib/pre_assembly/bundle.rb @@ -156,7 +156,7 @@ def new_object_file(stageable, file_path) # whether it matches the current file path. def exclude_from_content(file_path) return false unless content_exclusion - file_path =~ content_exclusion ? true : false + file_path&.match?(content_exclusion) ? true : false end # Takes a DigitalObject. For each of its ObjectFiles, diff --git a/app/lib/pre_assembly/digital_object.rb b/app/lib/pre_assembly/digital_object.rb index 2b477df2..a9b58648 100644 --- a/app/lib/pre_assembly/digital_object.rb +++ b/app/lib/pre_assembly/digital_object.rb @@ -259,7 +259,7 @@ def initialize_assembly_workflow # TODO: use dor-workflow-service gem for this (see #194) with_retries(max_tries: Dor::Config.dor_services.num_attempts, rescue: Exception, handler: retry_handler('INITIALIZE_ASSEMBLY_WORKFLOW', method(:log))) do RestClient.post(assembly_workflow_url, {}).tap do |result| - next if result && (200..204).include?(result.code) + next if result && (200..204).cover?(result.code) raise "POST #{assembly_workflow_url} returned #{result.code}" end end diff --git a/spec/controllers/bundle_contexts_controller_spec.rb b/spec/controllers/bundle_contexts_controller_spec.rb index 8f50f172..a3ec40d5 100644 --- a/spec/controllers/bundle_contexts_controller_spec.rb +++ b/spec/controllers/bundle_contexts_controller_spec.rb @@ -61,14 +61,14 @@ it "fails if job_type is nil" do Dir.delete(output_dir) if Dir.exist?(output_dir) - params[:bundle_context].merge!(job_runs_attributes: { "0" => { job_type: "" } }) + params[:bundle_context][:job_runs_attributes] = { "0" => { job_type: "" } } expect { post :create, params: params }.not_to change(JobRun, :count) end end context "Invalid Parameters" do it 'do not create objects' do - params[:bundle_context].merge!(project_name: nil) + params[:bundle_context][:project_name] = nil expect { post :create, params: params }.not_to change(BundleContext, :count) expect do post :create, params: { bundle_context: { From fe02dc87ba432bddb6286d558b0dc2fa0586dace Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 26 Sep 2018 16:14:43 -0700 Subject: [PATCH 8/8] rubocop --auto-gen-config for updated status --- .rubocop_todo.yml | 551 +++++----------------------------------------- 1 file changed, 55 insertions(+), 496 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5591f07d..2b0610b8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,184 +1,44 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-09-12 16:22:49 -0700 using RuboCop version 0.59.0. +# on 2018-09-26 16:12:20 -0700 using RuboCop version 0.59.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_parameter, with_fixed_indentation -Layout/AlignParameters: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'app/lib/pre_assembly/logging.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'config/initializers/config.rb' - - 'spec/controllers/bundle_context_controller_spec.rb' - - 'spec/jobs/discovery_report_job_spec.rb' - - 'spec/jobs/preassembly_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/spec_helper.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'app/controllers/bundle_context_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundModuleBody: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Layout/LeadingCommentSpace: - Exclude: - - 'app/models/bundle_context.rb' - -# Offense count: 16 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Layout/SpaceAroundOperators: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'spec/models/bundle_context_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideArrayLiteralBrackets: - Exclude: - - 'app/models/bundle_context.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'spec/models/bundle_context_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'app/models/bundle_context.rb' - - 'spec/models/user_spec.rb' - -# Offense count: 2 -Lint/DuplicateMethods: - Exclude: - - 'app/lib/pre_assembly/object_file.rb' - -# Offense count: 1 -Lint/ParenthesesAsGroupedExpression: - Exclude: - - 'app/lib/pre_assembly/reporting_old.rb' - -# Offense count: 8 -Lint/RescueException: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/reporting.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. -Lint/UnusedMethodArgument: - Exclude: - - 'app/jobs/discovery_report_job.rb' - - 'app/jobs/preassembly_job.rb' - - 'app/lib/pre_assembly/digital_object.rb' - - 'app/lib/pre_assembly/reporting.rb' - -# Offense count: 4 -Lint/UselessAssignment: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - - 'app/lib/pre_assembly/smpl.rb' - -# Offense count: 18 +# Offense count: 9 Metrics/AbcSize: - Max: 228 + Max: 74 -# Offense count: 22 +# Offense count: 27 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 341 + Max: 309 # Offense count: 2 -# Configuration parameters: CountBlocks. -Metrics/BlockNesting: - Max: 4 - -# Offense count: 5 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 269 + Max: 190 -# Offense count: 9 +# Offense count: 4 Metrics/CyclomaticComplexity: - Max: 70 + Max: 20 -# Offense count: 11 +# Offense count: 4 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 338 + Max: 281 -# Offense count: 17 +# Offense count: 10 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 139 + Max: 44 -# Offense count: 1 -# Configuration parameters: CountComments. -Metrics/ModuleLength: - Max: 141 - -# Offense count: 8 +# Offense count: 3 Metrics/PerceivedComplexity: - Max: 73 + Max: 20 # Offense count: 7 # Configuration parameters: Blacklist. @@ -188,56 +48,25 @@ Naming/HeredocDelimiterNaming: - 'spec/lib/pre_assembly/digital_object_spec.rb' - 'spec/lib/pre_assembly/smpl_spec.rb' -# Offense count: 2 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -# MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: +# Offense count: 1 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: Exclude: - - 'spec/**/*' + - 'app/lib/pre_assembly/bundle.rb' -# Offense count: 2 +# Offense count: 1 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: io, id, to, by, on, in, at, ip, db Naming/UncommunicativeMethodParamName: Exclude: - - 'app/lib/pre_assembly/logging.rb' - 'spec/support/bundle_setup.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Performance/RangeInclude: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MaxKeyValuePairs. -Performance/RedundantMerge: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Performance/RegexpMatch: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - -# Offense count: 5 -RSpec/AnyInstance: - Exclude: - - 'spec/lib/bundle_context_temporary_spec.rb' - - 'spec/lib/pre_assembly/bundle_spec.rb' - - 'spec/services/discover_report_spec.rb' - - 'spec/views/discovery_report/show.text.erb_spec.rb' - # Offense count: 2 RSpec/DescribeClass: Exclude: - 'spec/views/bundle_context_spec.rb' - - 'spec/views/discovery_report/show.text.erb_spec.rb' + - 'spec/views/job_runs/index.json.jbuilder_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -247,21 +76,27 @@ RSpec/DescribedClass: Exclude: - 'spec/lib/pre_assembly/bundle_spec.rb' -# Offense count: 3 +# Offense count: 5 # Cop supports --auto-correct. RSpec/EmptyLineAfterFinalLet: Exclude: + - 'spec/controllers/bundle_contexts_controller_spec.rb' - 'spec/lib/pre_assembly/bundle_spec.rb' - - 'spec/services/discover_report_spec.rb' - - 'spec/views/discovery_report/show.text.erb_spec.rb' + - 'spec/models/bundle_context_spec.rb' + - 'spec/models/job_run_spec.rb' + - 'spec/services/discovery_report_spec.rb' -# Offense count: 1 +# Offense count: 5 # Cop supports --auto-correct. RSpec/EmptyLineAfterHook: Exclude: + - 'spec/jobs/discovery_report_job_spec.rb' + - 'spec/jobs/preassembly_job_spec.rb' - 'spec/lib/pre_assembly/bundle_spec.rb' + - 'spec/models/bundle_context_spec.rb' + - 'spec/models/job_run_spec.rb' -# Offense count: 1 +# Offense count: 2 # Configuration parameters: Max. RSpec/ExampleLength: Exclude: @@ -269,18 +104,10 @@ RSpec/ExampleLength: # Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: method_call, block -RSpec/ExpectChange: - Exclude: - - 'spec/models/bundle_context_spec.rb' - -# Offense count: 2 -# Configuration parameters: CustomTransform, IgnoreMethods. -RSpec/FilePath: +# Configuration parameters: CustomTransform, IgnoredWords. +RSpec/ExampleWording: Exclude: - - 'spec/jobs/preassembly_spec.rb' - - 'spec/services/discover_report_spec.rb' + - 'spec/controllers/bundle_contexts_controller_spec.rb' # Offense count: 3 # Cop supports --auto-correct. @@ -301,54 +128,36 @@ RSpec/InstanceVariable: # Cop supports --auto-correct. RSpec/LeadingSubject: Exclude: - - 'spec/services/discover_report_spec.rb' - - 'spec/views/discovery_report/show.text.erb_spec.rb' + - 'spec/models/bundle_context_spec.rb' + - 'spec/services/discovery_report_spec.rb' + +# Offense count: 1 +RSpec/LetSetup: + Exclude: + - 'spec/views/job_runs/index.json.jbuilder_spec.rb' # Offense count: 1 # Configuration parameters: AggregateFailuresByDefault. RSpec/MultipleExpectations: Max: 7 -# Offense count: 5 -RSpec/SubjectStub: - Exclude: - - 'spec/services/discover_report_spec.rb' - - 'spec/views/discovery_report/show.text.erb_spec.rb' - -# Offense count: 3 -# Configuration parameters: IgnoreSymbolicNames. -RSpec/VerifiedDoubles: - Exclude: - - 'spec/lib/pre_assembly/bundle_spec.rb' - # Offense count: 1 -# Cop supports --auto-correct. -Security/YAMLLoad: +RSpec/NamedSubject: Exclude: - - 'spec/support/bundle_setup.rb' + - 'spec/controllers/bundle_contexts_controller_spec.rb' -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: +# Offense count: 10 +RSpec/SubjectStub: Exclude: - - 'app/lib/pre_assembly/smpl.rb' - - 'spec/jobs/discovery_report_job_spec.rb' - - 'spec/jobs/preassembly_spec.rb' - - 'spec/lib/pre_assembly/bundle_spec.rb' + - 'spec/models/bundle_context_spec.rb' + - 'spec/services/discovery_report_spec.rb' # Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: +# Configuration parameters: IgnoreSymbolicNames. +RSpec/VerifiedDoubles: Exclude: - - 'config/deploy.rb' - 'spec/lib/pre_assembly/bundle_spec.rb' + - 'spec/models/job_run_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -363,285 +172,35 @@ Style/ClassVars: Exclude: - 'app/lib/pre_assembly/logging.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Keywords. -# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW -Style/CommentAnnotation: - Exclude: - - 'app/models/bundle_context.rb' - -# Offense count: 14 +# Offense count: 8 Style/CommentedKeyword: Exclude: - - 'app/lib/pre_assembly/project/smpl.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - 'app/lib/pre_assembly/smpl.rb' - - 'app/models/bundle_context.rb' - 'spec/lib/pre_assembly/smpl_spec.rb' -# Offense count: 21 +# Offense count: 19 Style/Documentation: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'app/controllers/bundle_context_controller.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Style/Encoding: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/digital_object.rb' - - 'app/lib/pre_assembly/reporting.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - - 'app/lib/pre_assembly/smpl.rb' - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'app/lib/pre_assembly/logging.rb' - - 'app/lib/pre_assembly/reporting.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - -# Offense count: 3 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/smpl.rb' - -# Offense count: 186 +# Offense count: 140 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys Style/HashSyntax: Exclude: - - 'app/lib/bundle_context_temporary.rb' - 'app/lib/csv_importer.rb' - 'app/lib/pre_assembly/bundle.rb' - 'app/lib/pre_assembly/digital_object.rb' - 'app/lib/pre_assembly/logging.rb' - - 'app/lib/pre_assembly/reporting.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - 'app/lib/pre_assembly/smpl.rb' - 'spec/lib/pre_assembly/bundle_spec.rb' - 'spec/lib/pre_assembly/digital_object_spec.rb' - 'spec/lib/pre_assembly/object_file_spec.rb' - 'spec/lib/pre_assembly/smpl_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -Style/MethodCallWithoutArgsParentheses: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline -Style/MethodDefParentheses: - Exclude: - - 'app/lib/pre_assembly/logging.rb' - -# Offense count: 1 -Style/MultipleComparison: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'app/lib/pre_assembly/digital_object.rb' - - 'app/lib/pre_assembly/logging.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: Whitelist. -# Whitelist: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - - 'spec/lib/pre_assembly/bundle_spec.rb' - - 'spec/lib/pre_assembly/digital_object_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 8 - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. -Style/ParenthesesAroundCondition: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/logging.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - - 'app/lib/pre_assembly/smpl.rb' - -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'config/deploy.rb' - - 'config/deploy/old_prod.rb' - - 'config/deploy/old_stage.rb' - - 'config/deploy/prod.rb' - - 'config/deploy/stage.rb' - - 'spec/lib/bundle_context_temporary_spec.rb' - - 'spec/lib/csv_importer_spec.rb' - - 'spec/lib/pre_assembly/bundle_spec.rb' - - 'spec/lib/pre_assembly/digital_object_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: short, verbose -Style/PreferredHashMethods: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'app/lib/pre_assembly/bundle.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/Proc: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantException: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'app/services/discovery_report.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'app/lib/pre_assembly/reporting_old.rb' - -# Offense count: 320 +# Offense count: 210 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/digital_object.rb' - - 'app/lib/pre_assembly/reporting.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - - 'spec/lib/pre_assembly/digital_object_spec.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex -Style/TernaryParentheses: - Exclude: - - 'app/lib/pre_assembly/reporting.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - - 'app/lib/pre_assembly/smpl.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'spec/lib/pre_assembly/bundle_spec.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/logging.rb' - - 'spec/lib/pre_assembly/bundle_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist. -# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym -Style/TrivialAccessors: - Exclude: - - 'app/lib/pre_assembly/object_file.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/UnneededInterpolation: - Exclude: - - 'spec/lib/pre_assembly/digital_object_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/WhileUntilDo: - Exclude: - - 'app/lib/pre_assembly/bundle.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinSize, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - Exclude: - - 'app/lib/pre_assembly/digital_object.rb' - - 'app/lib/pre_assembly/smpl.rb' - - 'spec/lib/pre_assembly/smpl_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -Style/ZeroLengthPredicate: - Exclude: - - 'app/lib/bundle_context_temporary.rb' - - 'app/lib/pre_assembly/bundle.rb' - - 'app/lib/pre_assembly/digital_object.rb' - - 'app/lib/pre_assembly/reporting_old.rb' - - 'app/lib/pre_assembly/smpl.rb'