Module: Sensu::API::Utilities::FilterResponseContent
- Includes:
- Utilities
- Defined in:
- lib/sensu/api/utilities/filter_response_content.rb
Constant Summary
Constants included from Utilities
Instance Method Summary collapse
-
#dot_notation_to_hash(dot_notation, value) ⇒ Hash
Create a nested hash from a dot notation key and value.
-
#filter_response_content! ⇒ Object
Filter the response content if filter parameters have been provided.
Methods included from Utilities
#attributes_match?, #check_subdued?, #deep_merge, #determine_check_cron_time, #eval_attribute_value, #find_attribute_value, #in_time_window?, #in_time_windows?, #object_substitute_tokens, #process_cpu_times, #process_eval_string, #random_uuid, #redact_sensitive, #retry_until_true, #substitute_tokens, #system_address, #system_hostname, #testing?
Instance Method Details
#dot_notation_to_hash(dot_notation, value) ⇒ Hash
Create a nested hash from a dot notation key and value.
14 15 16 17 18 19 20 21 22 23 24 |
# 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! ⇒ Object
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.
30 31 32 33 34 35 36 37 38 39 40 |
# 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 |