Class: ActiveZuora::ArrayFieldDecorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveZuora::ArrayFieldDecorator
- Defined in:
- lib/active_zuora/fields/array_field_decorator.rb
Instance Method Summary collapse
- #build_xml(xml, soap, values, options = {}) ⇒ Object
- #clear_changed_attributes(values) ⇒ Object
-
#type_cast(values) ⇒ Object
Wraps a Field object and typecasts/builds item as an array of the given field.
Instance Method Details
#build_xml(xml, soap, values, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_zuora/fields/array_field_decorator.rb', line 12 def build_xml(xml, soap, values, ={}) # It may be wierd that we're mapping and taking the last value, # But there's an issue with xml builder where if a block # returns an array, it will output the array in the XML. # So instead, we'll have our block return the value # of the last build_xml call. [values].flatten.compact.map do |value| __getobj__.build_xml(xml, soap, value, ) end.last end |
#clear_changed_attributes(values) ⇒ Object
23 24 25 |
# File 'lib/active_zuora/fields/array_field_decorator.rb', line 23 def clear_changed_attributes(values) [values].flatten.compact.map { |value| __getobj__.clear_changed_attributes(value) } end |
#type_cast(values) ⇒ Object
Wraps a Field object and typecasts/builds item as an array of the given field.
7 8 9 10 |
# File 'lib/active_zuora/fields/array_field_decorator.rb', line 7 def type_cast(values) # Force into an array and run type_cast on each element. [values].flatten.compact.map { |value| __getobj__.type_cast(value) } end |