Class: Humidifier::Props::ListProp
- Defined in:
- lib/humidifier/props/list_prop.rb
Overview
A property that is contained in a list
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(list) ⇒ Object
converts the value through mapping using the subprop unless it is valid.
-
#to_cf(list) ⇒ Object
CFN stack syntax.
-
#valid?(list) ⇒ Boolean
Valid if the value is whitelisted or every value in the list 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/list_prop.rb', line 7 def subprop @subprop end |
Instance Method Details
#convert(list) ⇒ Object
converts the value through mapping using the subprop unless it is valid
10 11 12 |
# File 'lib/humidifier/props/list_prop.rb', line 10 def convert(list) valid?(list) ? list : list.map { |value| subprop.convert(value) } end |
#to_cf(list) ⇒ Object
CFN stack syntax
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/humidifier/props/list_prop.rb', line 15 def to_cf(list) cf_value = if list.respond_to?(:to_cf) list.to_cf else list.map { |value| subprop.to_cf(value).last } end [key, cf_value] end |
#valid?(list) ⇒ Boolean
Valid if the value is whitelisted or every value in the list is valid on the subprop
28 29 30 31 32 |
# File 'lib/humidifier/props/list_prop.rb', line 28 def valid?(list) return true if whitelisted_value?(list) list.is_a?(Enumerable) && list.all? { |value| subprop.valid?(value) } end |