Module: RejectDeeplyNested
- Defined in:
- lib/reject_deeply_nested.rb,
lib/reject_deeply_nested/version.rb
Constant Summary collapse
- DEFAULT_IGNORE_VALUES =
[/_destroy/]
- BLANK =
proc { |attributes| deep_blank?(attributes) }
- SMART_BLANK =
proc do |ignore_values, attributes| deep_blank?(attributes, Array(ignore_values) + DEFAULT_IGNORE_VALUES) end
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.deep_blank?(hash, ignore_values = DEFAULT_IGNORE_VALUES) ⇒ Boolean
Recursively traverse nested attributes to define is all values blank.
Class Method Details
.deep_blank?(hash, ignore_values = DEFAULT_IGNORE_VALUES) ⇒ Boolean
Recursively traverse nested attributes to define is all values blank. Additionaly considers that value with _destroy key is always blank.
16 17 18 19 20 21 22 23 |
# File 'lib/reject_deeply_nested.rb', line 16 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 |