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



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/convection/model/template.rb', line 140

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