Skip to content

Commit

Permalink
refactor: extract escape_wildcards method
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 19, 2023
1 parent 7dbf5be commit 749b464
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/pact_broker/repositories/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ def name_like column_name, value
if PactBroker.configuration.use_case_sensitive_resource_names
if mysql?
# sigh, mysql, this is the only way to perform a case sensitive search
Sequel.like(column_name, value.gsub("_", "\\_"), { case_insensitive: false })
Sequel.like(column_name, escape_wildcards(value), { case_insensitive: false })
else
{ column_name => value }
end
else
Sequel.like(column_name, value.gsub("_", "\\_"), { case_insensitive: true })
Sequel.like(column_name, escape_wildcards(value), { case_insensitive: true })
end
end

def mysql?
Sequel::Model.db.adapter_scheme.to_s =~ /mysql/
end



def postgres?
Sequel::Model.db.adapter_scheme.to_s =~ /postgres/
end

def escape_wildcards(value)
value.gsub("_", "\\_").gsub("%", "\\%")
end

private :escape_wildcards
end
end
end

0 comments on commit 749b464

Please sign in to comment.