Class: Humidifier::Props::MapProp

Inherits:
Base
  • Object
show all
Defined in:
lib/humidifier/props/map_prop.rb

Overview

A property that is contained in a Map

Constant Summary

Constants inherited from Base

Base::WHITELIST

Instance Attribute Summary collapse

Attributes inherited from Base

#key, #name, #spec, #substructs

Instance Method Summary collapse

Methods inherited from Base

#documentation, #initialize, #required?, #update_type, #whitelisted_value?

Constructor Details

This class inherits a constructor from Humidifier::Props::Base

Instance Attribute Details

#subpropObject (readonly)

Returns the value of attribute subprop.



5
6
7
# File 'lib/humidifier/props/map_prop.rb', line 5

def subprop
  @subprop
end

Instance Method Details

#convert(map) ⇒ Object

converts the value through mapping using the subprop unless it is valid



8
9
10
# File 'lib/humidifier/props/map_prop.rb', line 8

def convert(map)
  valid?(map) ? map : Utils.enumerable_to_h(map) { |(key, value)| [key, subprop.convert(value)] }
end

#to_cf(map) ⇒ Object

CFN stack syntax



13
14
15
16
17
18
19
# File 'lib/humidifier/props/map_prop.rb', line 13

def to_cf(map)
  dumped =
    Utils.enumerable_to_h(map) do |(subkey, subvalue)|
      [subkey, subprop.to_cf(subvalue).last]
    end
  [key, dumped]
end

#valid?(map) ⇒ Boolean

Valid if the value is whitelisted or every value in the map is valid on the subprop

Returns:

  • (Boolean)


22
23
24
# File 'lib/humidifier/props/map_prop.rb', line 22

def valid?(map)
  whitelisted_value?(map) || (map.is_a?(Hash) && map.values.all? { |value| subprop.valid?(value) })
end