Module: Msf::Util::DBManager
- Defined in:
- lib/msf/util/db_manager.rb
Class Method Summary collapse
-
.create_all_column_search_conditions(model, search, column_name_skip_list = nil) ⇒ Object
Creates search conditions to match the specified search string against all of the model’s columns.
-
.process_opts_workspace(opts, framework, required = true) ⇒ Mdm::Workspace
Processes the workspace value in the opts hash from a request.
Class Method Details
.create_all_column_search_conditions(model, search, column_name_skip_list = nil) ⇒ Object
Creates search conditions to match the specified search string against all of the model’s columns.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/msf/util/db_manager.rb', line 10 def self.create_all_column_search_conditions(model, search, column_name_skip_list=nil) search = "(?mi)#{search}" # 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)) } Arel::Nodes::Grouping.new(condition_set.reduce { |conditions, condition| conditions.or(condition).expr }) end |
.process_opts_workspace(opts, framework, required = true) ⇒ Mdm::Workspace
Processes the workspace value in the opts hash from a request. This method throws an exception if :workspace was not present but required was true, deletes the workspace from the hash, and looks up the workspace object by name, which it returns.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/msf/util/db_manager.rb', line 34 def self.process_opts_workspace(opts, framework, required = true) wspace = opts[:workspace] if required && (wspace.nil? || (wspace.kind_of?(String) && wspace.empty?)) raise ArgumentError.new("opts must include a valid :workspace") end case wspace when Hash workspace_name = wspace[:name] when String workspace_name = wspace when Mdm::Workspace workspace_name = wspace.name else workspace_name = nil end wspace = framework.db.find_workspace(workspace_name) unless workspace_name.nil? raise "Couldn't find workspace #{workspace_name}" if wspace.nil? && required wspace end |