Skip to content

Commit

Permalink
Fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gbmoretti committed Sep 29, 2023
1 parent 8fc96a0 commit 8033627
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 110 deletions.
8 changes: 8 additions & 0 deletions packages/ostruct-sanitizer/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require:
- rubocop-powerhome

AllCops:
TargetRubyVersion: 2.6

Style/OpenStructUse:
Enabled: false
9 changes: 7 additions & 2 deletions packages/ostruct-sanitizer/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in ostruct-sanitizer.gemspec
gemspec

gem "bundler", "~> 2.4.7"
gem "byebug"
gem "rake", "~> 10.0"
gem "rspec", "~> 3.0"
gem "rubocop-powerhome", "0.5.0"
6 changes: 3 additions & 3 deletions packages/ostruct-sanitizer/Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require "bundler/gem_tasks"

require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

require 'rubocop/rake_task'
require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop)

task default: %i[rubocop spec]
17 changes: 11 additions & 6 deletions packages/ostruct-sanitizer/lib/ostruct/sanitizer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'ostruct'
require 'ostruct/sanitizer/version'
require "ostruct"
require "ostruct/sanitizer/version"

module OStruct
# Provides a series of sanitization rules to be applied on OpenStruct fields on
Expand Down Expand Up @@ -55,6 +55,10 @@ def method_missing(method, *args)
send(method, args[0])
end

def respond_to_missing?(method)
setter?(method)
end

# Set attribute's value via setter so that any existing sanitization rules
# may be applied
#
Expand All @@ -65,7 +69,7 @@ def []=(name, value)
send("#{name}=", value)
end

private
private

def setter?(method)
method[/.*(?==\z)/m].to_s.to_sym
Expand Down Expand Up @@ -98,7 +102,8 @@ module ClassMethods
# Registers a sanitization block for a given field
#
# @param [Array<Symbol>] a list of field names to be sanitized
# @param [#call] block sanitization block to be applied to the current value of each field and returns the new sanitized value
# @param [#call] block sanitization block to be applied to the current value of each field
# and returns the new sanitized value
#
def sanitize(*fields, &block)
@sanitizers ||= {}
Expand All @@ -125,7 +130,7 @@ def truncate(*fields, length:, strip_whitespaces: true)
# @param [Array<Symbol>] a list of field names to be sanitized
#
def alphanumeric(*fields)
sanitize(*fields) { |value| value.gsub(/[^A-Za-z0-9\s]/, '') }
sanitize(*fields) { |value| value.gsub(/[^A-Za-z0-9\s]/, "") }
end

# Strips out leading and trailing spaces from the values of the given fields
Expand All @@ -141,7 +146,7 @@ def strip(*fields)
# @param [Array<Symbol>] fields list of fields to be sanitized
#
def digits(*fields)
sanitize(*fields) { |value| value.to_s.gsub(/[^0-9]/, '') }
sanitize(*fields) { |value| value.to_s.gsub(/[^0-9]/, "") }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module OStruct
module Sanitizer
VERSION = '0.7.0'
VERSION = "0.7.0"
end
end
31 changes: 13 additions & 18 deletions packages/ostruct-sanitizer/ostruct-sanitizer.gemspec
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'ostruct/sanitizer/version'
require "ostruct/sanitizer/version"

Gem::Specification.new do |spec|
spec.name = 'ostruct-sanitizer'
spec.name = "ostruct-sanitizer"
spec.version = OStruct::Sanitizer::VERSION
spec.authors = ['Diego Borges']
spec.email = ['[email protected]']
spec.authors = ["Diego Borges"]
spec.email = ["[email protected]"]

spec.summary = 'Provides Rails-like sanitization rules for OpenStruct fields.'
spec.description = 'Provides Rails-like sanitization rules for OpenStruct fields.'
spec.homepage = 'https://github.com/powerhome/ostruct-sanitizer'
spec.license = 'MIT'
spec.summary = "Provides Rails-like sanitization rules for OpenStruct fields."
spec.description = "Provides Rails-like sanitization rules for OpenStruct fields."
spec.homepage = "https://github.com/powerhome/ostruct-sanitizer"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = 'exe'
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.required_ruby_version = '>= 2.6'

spec.add_development_dependency 'bundler', '~> 2.4.7'
spec.add_development_dependency 'byebug'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop-powerhome', '0.5.0'
spec.required_ruby_version = ">= 2.6"
spec.metadata["rubygems_mfa_required"] = "true"
end
Loading

0 comments on commit 8033627

Please sign in to comment.