module RejectDeeplyNested

Constants

ANY_MISSED
BLANK
DEFAULT_IGNORE_VALUES
SMART_BLANK
VERSION

Public Class Methods

blank?(ignore_values: []) click to toggle source
# File lib/reject_deeply_nested.rb, line 19
def self.blank?(ignore_values: [])
  SMART_BLANK.curry.(ignore_values)
end
has_missed_fields?(fields) click to toggle source
# File lib/reject_deeply_nested.rb, line 15
def self.has_missed_fields?(fields)
  ANY_MISSED.curry.(Array(fields))
end

Private Class Methods

deep_blank?(hash, ignore_values = DEFAULT_IGNORE_VALUES) click to toggle source

Recursively traverse nested attributes to define is all values blank. Additionaly considers that value with _destroy key is always blank.

# File lib/reject_deeply_nested.rb, line 27
def self.deep_blank?(hash, ignore_values = DEFAULT_IGNORE_VALUES)
  hash.each do |key, value|
    next if ignore_values.any? { |ignore_value| key =~ ignore_value }
    any_blank = value.is_a?(Hash) ? deep_blank?(value, ignore_values) : value.blank?
    return false unless any_blank
  end
  true
end