Class: Humidifier::Props::StructureProp
- Defined in:
- lib/humidifier/props/structure_prop.rb
Overview
A structure property that references a structure from the specification
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#subprops ⇒ Object
readonly
Returns the value of attribute subprops.
Attributes inherited from Base
#key, #name, #spec, #substructs
Instance Method Summary collapse
-
#convert(struct) ⇒ Object
converts the value through mapping using the subprop unless it is valid.
-
#to_cf(struct) ⇒ Object
CFN stack syntax.
-
#valid?(struct) ⇒ Boolean
true if the value is whitelisted or Hash and all keys are valid for their corresponding props.
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
#subprops ⇒ Object (readonly)
Returns the value of attribute subprops.
7 8 9 |
# File 'lib/humidifier/props/structure_prop.rb', line 7 def subprops @subprops end |
Instance Method Details
#convert(struct) ⇒ Object
converts the value through mapping using the subprop unless it is valid
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/humidifier/props/structure_prop.rb', line 10 def convert(struct) if valid?(struct) struct else struct.map do |subkey, subvalue| subkey = Utils.underscore(subkey.to_s) [subkey.to_sym, subprops[subkey].convert(subvalue)] end.to_h end end |
#to_cf(struct) ⇒ Object
CFN stack syntax
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/humidifier/props/structure_prop.rb', line 22 def to_cf(struct) cf_value = if struct.respond_to?(:to_cf) struct.to_cf else struct.map do |subkey, subvalue| subprops[subkey.to_s].to_cf(subvalue) end.to_h end [key, cf_value] end |
#valid?(struct) ⇒ Boolean
true if the value is whitelisted or Hash and all keys are valid for their corresponding props
37 38 39 40 41 |
# File 'lib/humidifier/props/structure_prop.rb', line 37 def valid?(struct) return true if whitelisted_value?(struct) struct.is_a?(Hash) && valid_struct?(struct) end |