Class: Humidifier::Props::StructureProp

Inherits:
Base
  • Object
show all
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

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

#subpropsObject (readonly)

Returns the value of attribute subprops.



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

def subprops
  @subprops
end

Instance Method Details

#convert(struct) ⇒ Object

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



8
9
10
11
12
13
14
15
16
17
# File 'lib/humidifier/props/structure_prop.rb', line 8

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



20
21
22
# File 'lib/humidifier/props/structure_prop.rb', line 20

def to_cf(struct)
  [key, struct.map { |subkey, subvalue| subprops[subkey.to_s].to_cf(subvalue) }.to_h]
end

#valid?(struct) ⇒ Boolean

true if the value is whitelisted or Hash and all keys are valid for their corresponding props

Returns:

  • (Boolean)


25
26
27
# File 'lib/humidifier/props/structure_prop.rb', line 25

def valid?(struct)
  whitelisted_value?(struct) || (struct.is_a?(Hash) && valid_struct?(struct))
end