Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split falsepositve concern #1024

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mihari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
require "mihari/concerns/configurable"
require "mihari/concerns/database_connectable"
require "mihari/concerns/error_unwrappable"
require "mihari/concerns/falsepositive_normalizable"
require "mihari/concerns/falsepositive_validatable"
require "mihari/concerns/refangable"
require "mihari/concerns/retriable"
Expand Down
30 changes: 30 additions & 0 deletions lib/mihari/concerns/falsepositive_normalizable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Mihari
module Concerns
#
# False positive normalizable concern
#
module FalsePositiveNormalizable
extend ActiveSupport::Concern

prepend MemoWise

#
# Normalize a falsepositive value
#
# @param [String] value
#
# @return [String, Regexp]
#
def normalize_falsepositive(value)
return value if !value.start_with?("/") || !value.end_with?("/")

# if a value is surrounded by slashes, take it as a regexp
value_without_slashes = value[1..-2]
Regexp.compile value_without_slashes.to_s
end
memo_wise :normalize_falsepositive
end
end
end
18 changes: 1 addition & 17 deletions lib/mihari/concerns/falsepositive_validatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,7 @@ module Concerns
module FalsePositiveValidatable
extend ActiveSupport::Concern

prepend MemoWise

#
# Normalize a falsepositive value
#
# @param [String] value
#
# @return [String, Regexp]
#
def normalize_falsepositive(value)
return value if !value.start_with?("/") || !value.end_with?("/")

# if a value is surrounded by slashes, take it as a regexp
value_without_slashes = value[1..-2]
Regexp.compile value_without_slashes.to_s
end
memo_wise :normalize_falsepositive
include FalsePositiveNormalizable

#
# Check whether a value is valid format as a disallowed data value
Expand Down