Add optional parameter to skip columns
parent
f10924a5c0
commit
4c536a1819
|
@ -5,13 +5,19 @@ module Msf
|
|||
#
|
||||
# @param model - An ActiveRecord model object
|
||||
# @param search - A string regex search
|
||||
# @param column_name_skip_list - An array of strings containing column names to skip
|
||||
# @return Arel::Nodes::Or object that represents a search of all of the model's columns
|
||||
def self.create_all_column_search_conditions(model, search)
|
||||
def self.create_all_column_search_conditions(model, search, column_name_skip_list=nil)
|
||||
search = "(?mi)#{search}"
|
||||
condition_set = model.columns.map do |column|
|
||||
# remove skip columns
|
||||
columns = model.columns.reject { |column|
|
||||
column_name_skip_list && column_name_skip_list.include?(column.name)
|
||||
}
|
||||
|
||||
condition_set = columns.map { |column|
|
||||
Arel::Nodes::Regexp.new(Arel::Nodes::NamedFunction.new("CAST", [model.arel_table[column.name].as("TEXT")]),
|
||||
Arel::Nodes.build_quoted(search))
|
||||
end
|
||||
}
|
||||
condition_set.reduce { |conditions, condition| conditions.or(condition).expr }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue