Class: Humidifier::Props::MapProp

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

Constant Summary

Constants inherited from Prop

Prop::WHITELIST

Instance Attribute Summary collapse

Attributes inherited from Prop

#key, #name, #spec

Instance Method Summary collapse

Methods inherited from Prop

allow_type, allowed_types, #documentation, #required?, #update_type

Constructor Details

#initialize(key, spec = {}, substructs = {}) ⇒ MapProp

Returns a new instance of MapProp.


109
110
111
112
# File 'lib/humidifier/props.rb', line 109

def initialize(key, spec = {}, substructs = {})
  super(key, spec)
  @subprop = Props.singular_from(key, spec, substructs)
end

Instance Attribute Details

#subpropObject (readonly)

Returns the value of attribute subprop


107
108
109
# File 'lib/humidifier/props.rb', line 107

def subprop
  @subprop
end

Instance Method Details

#to_cf(map) ⇒ Object


114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/humidifier/props.rb', line 114

def to_cf(map)
  cf_value =
    if map.respond_to?(:to_cf)
      map.to_cf
    else
      map.map do |subkey, subvalue|
        [subkey, subprop.to_cf(subvalue).last]
      end.to_h
    end

  [key, cf_value]
end

#valid?(map) ⇒ Boolean

Returns:

  • (Boolean)

127
128
129
130
131
# File 'lib/humidifier/props.rb', line 127

def valid?(map)
  return true if super(map)

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