module Sensu::API::Utilities::FilterResponseContent

Public Instance Methods

dot_notation_to_hash(dot_notation, value) click to toggle source

Create a nested hash from a dot notation key and value.

@param dot_notation [String] @param value [Object] @return [Hash]

# File lib/sensu/api/utilities/filter_response_content.rb, line 14
def dot_notation_to_hash(dot_notation, value)
  hash = {}
  dot_notation.split(".").reverse.each do |key|
    if hash.empty?
      hash = {key.to_sym => value}
    else
      hash = {key.to_sym => hash}
    end
  end
  hash
end
filter_response_content!() click to toggle source

Filter the response content if filter parameters have been provided. This method mutates `@response_content`, only retaining array items that match the attributes provided via filter parameters.

# File lib/sensu/api/utilities/filter_response_content.rb, line 30
def filter_response_content!
  if @response_content.is_a?(Array) && !@filter_params.empty?
    attributes = {}
    @filter_params.each do |key, value|
      attributes = deep_merge(attributes, dot_notation_to_hash(key, value))
    end
    @response_content.select! do |object|
      attributes_match?(object, attributes, false)
    end
  end
end