Class: SaxStream::Internal::Mappings::Child

Inherits:
Base
  • Object
show all
Defined in:
lib/sax_stream/internal/mappings/child.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#find_or_insert_parent_node, #map_value_onto_object, #path_parts

Constructor Details

#initialize(name, options) ⇒ Child

Supported options are :to, :as & :parent_collects. See Mapper.relate documentation for more details.



10
11
12
13
# File 'lib/sax_stream/internal/mappings/child.rb', line 10

def initialize(name, options)
  @parent_collects = options[:parent_collects]
  super
end

Instance Method Details

#build_empty_relationObject



25
26
27
# File 'lib/sax_stream/internal/mappings/child.rb', line 25

def build_empty_relation
  [] if @plural
end

#handler_for(node_path, collector, handler_stack, parent_object) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/sax_stream/internal/mappings/child.rb', line 15

def handler_for(node_path, collector, handler_stack, parent_object)
  node_name = node_path.split('/').last
  @mapper_classes.each do |mapper_class|
    if mapper_class.maps_node?(node_name)
      return MapperHandler.new(mapper_class, child_collector(parent_object, collector), handler_stack)
    end
  end
  nil
end

#update_parent_node(builder, doc, parent, object) ⇒ Object



29
30
31
32
33
# File 'lib/sax_stream/internal/mappings/child.rb', line 29

def update_parent_node(builder, doc, parent, object)
  value_from_object(object).each do |child_object|
    parent << builder.build_xml_for(child_object, parent)
  end
end