From 5e2d2b2477b95bdd97e7c82151387107a0c7b00e Mon Sep 17 00:00:00 2001 From: Wes Oldenbeuving Date: Wed, 28 Sep 2022 10:34:00 +0200 Subject: [PATCH] Addressed Rubocop concerns from PR 29 Rubocop checks in PR #29 did not fire, so issues were not discovered until release. This corrects them, making Rubocop and tests pass. - GTIN module was 31 lines (max 30), so I inlined a guard clause - Use of redundant `self.` was removed - Prefer `__send__` over `send` when `public_send` is not an option --- lib/barcodevalidation/gtin.rb | 4 +--- lib/barcodevalidation/gtin/base.rb | 2 +- spec/lib/barcodevalidation/gtin_spec.rb | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/barcodevalidation/gtin.rb b/lib/barcodevalidation/gtin.rb index 2104685..838640a 100644 --- a/lib/barcodevalidation/gtin.rb +++ b/lib/barcodevalidation/gtin.rb @@ -15,9 +15,7 @@ def new(input) # Adds the provided class to the back of the list of prioritized GTIN classes. def append_gtin_class(gtin_class) - return if gtin_class?(gtin_class) - - prioritized_gtin_classes.push(gtin_class) + prioritized_gtin_classes.push(gtin_class) unless gtin_class?(gtin_class) nil end diff --git a/lib/barcodevalidation/gtin/base.rb b/lib/barcodevalidation/gtin/base.rb index a6bccf5..f2a0228 100644 --- a/lib/barcodevalidation/gtin/base.rb +++ b/lib/barcodevalidation/gtin/base.rb @@ -22,7 +22,7 @@ def initialize(input) # Does this class (potentially) handle a GTIN that matches the input? # Subclasses can choose to implement their own logic. The default is to look at +VALID_LENGTH+ and use that to match the length of the input the class handles. def self.handles?(input) - return false unless self.const_defined?(:VALID_LENGTH) + return false unless const_defined?(:VALID_LENGTH) input.length == self::VALID_LENGTH end diff --git a/spec/lib/barcodevalidation/gtin_spec.rb b/spec/lib/barcodevalidation/gtin_spec.rb index b0a913f..c179dac 100644 --- a/spec/lib/barcodevalidation/gtin_spec.rb +++ b/spec/lib/barcodevalidation/gtin_spec.rb @@ -124,7 +124,7 @@ class_obj = Object.const_get(class_sym) BarcodeValidation::GTIN.remove_gtin_class(class_obj) - Object.send(:remove_const, class_sym) + Object.__send__(:remove_const, class_sym) end end