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 = {}, subprop = nil) ⇒ MapProp

Returns a new instance of MapProp.



145
146
147
148
# File 'lib/humidifier/props.rb', line 145

def initialize(key, spec = {}, subprop = nil)
  super(key, spec)
  @subprop = subprop
end

Instance Attribute Details

#subpropObject (readonly)

Returns the value of attribute subprop.



143
144
145
# File 'lib/humidifier/props.rb', line 143

def subprop
  @subprop
end

Instance Method Details

#pretty_print(q) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/humidifier/props.rb', line 150

def pretty_print(q)
  q.group do
    q.text("(#{name}=map")
    q.nest(2) do
      q.breakable
      q.pp(subprop)
    end
    q.breakable("")
    q.text(")")
  end
end

#to_cf(map) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/humidifier/props.rb', line 162

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

  [key, cf_value]
end

#valid?(map) ⇒ Boolean

Returns:

  • (Boolean)


175
176
177
178
179
# File 'lib/humidifier/props.rb', line 175

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

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