Class: GlobalCollect::Requests::Composite

Inherits:
Base
  • Object
show all
Defined in:
lib/global_collect/requests/composite.rb

Instance Attribute Summary

Attributes inherited from Base

#action, #suggested_response_mixins, #version

Instance Method Summary collapse

Methods inherited from Base

#default_xml_encoding_options

Constructor Details

#initialize(action, model_builder_pairs) ⇒ Composite

Returns a new instance of Composite.



4
5
6
7
8
9
10
11
# File 'lib/global_collect/requests/composite.rb', line 4

def initialize(action, model_builder_pairs)
  unless model_builder_pairs.map(&:size).uniq == [2]
    raise ArgumentError.new("Models and builders must be in array pairs like [[model,builder_class],...]!")
  end
  @contents = model_builder_pairs
  super(action)
  @suggested_response_mixins = model_builder_pairs.map(&:first).map(&:suggested_response_mixins).flatten.uniq
end

Instance Method Details

#to_xmlObject



13
14
15
16
17
18
19
20
21
# File 'lib/global_collect/requests/composite.rb', line 13

def to_xml
  super do |params_node|
    @contents.each do |model,builder_class|
      raise "Invalid model #{model.inspect}. Errors: #{model.errors.inspect}!" unless model.validate
      builder = builder_class.new(model)
      builder.build(params_node) 
    end
  end
end