Skip to content

Commit

Permalink
refactor: split falsepositve concern
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Jan 14, 2024
1 parent 3fdcb38 commit bed92a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
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

0 comments on commit bed92a1

Please sign in to comment.