Class: Convection::Model::Collection

Inherits:
Hash
  • Object
show all
Defined in:
lib/convection/model/template.rb

Overview

Mapable hash

Instance Method Summary collapse

Methods inherited from Hash

#diff, #properties

Instance Method Details

#map(no_nil = false, &block) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/convection/model/template.rb', line 102

def map(no_nil = false, &block)
  result = {}

  each do |key, value|
    res = block.call(value)

    next if no_nil && res.nil?
    next if no_nil && res.is_a?(Array) && res.empty?
    next if no_nil && res.is_a?(Hash) && res.empty?

    result[key] = res
  end

  result
end