Class: Humidifier::Props::MapProp
- Defined in:
- lib/humidifier/props/map_prop.rb
Overview
A property that is contained in a Map
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#subprop ⇒ Object
readonly
Returns the value of attribute subprop.
Attributes inherited from Base
#key, #name, #spec, #substructs
Instance Method Summary collapse
-
#convert(map) ⇒ Object
converts the value through mapping using the subprop unless it is valid.
-
#to_cf(map) ⇒ Object
CFN stack syntax.
-
#valid?(map) ⇒ Boolean
Valid if the value is whitelisted or every value in the map is valid on the subprop.
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
#subprop ⇒ Object (readonly)
Returns the value of attribute subprop.
7 8 9 |
# File 'lib/humidifier/props/map_prop.rb', line 7 def subprop @subprop end |
Instance Method Details
#convert(map) ⇒ Object
converts the value through mapping using the subprop unless it is valid
10 11 12 13 14 |
# File 'lib/humidifier/props/map_prop.rb', line 10 def convert(map) return map if valid?(map) map.map { |key, value| [key, subprop.convert(value)] }.to_h end |
#to_cf(map) ⇒ Object
CFN stack syntax
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/humidifier/props/map_prop.rb', line 17 def to_cf(map) cf_value = if map.respond_to?(:to_cf) map.to_cf else map.each_with_object({}) do |(subkey, subvalue), serialized| serialized[subkey] = subprop.to_cf(subvalue).last end end [key, cf_value] end |
#valid?(map) ⇒ Boolean
Valid if the value is whitelisted or every value in the map is valid on the subprop
32 33 34 35 36 |
# File 'lib/humidifier/props/map_prop.rb', line 32 def valid?(map) return true if whitelisted_value?(map) map.is_a?(Hash) && map.values.all? { |value| subprop.valid?(value) } end |