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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/convection/model/template.rb', line 124

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