Method: Representable::XML::Namespace#to_node

Defined in:
lib/representable/xml/namespace.rb

#to_node(options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/representable/xml/namespace.rb', line 85

def to_node(options={})
  local_uri = representable_attrs.options[:local_namespace] # every decorator MUST have a local namespace.
  prefix    = self.class.namespace_defs[local_uri]

  root_tag = [prefix, representation_wrap(options)].compact.join(":")

  options = { wrap: root_tag }.merge(options)

  # TODO: there should be an easier way to pass a set of options to all nested #to_node decorators.
  representable_attrs.keys.each do |property|
    options[property.to_sym] = { show_definition: false, namespaces: options[:namespaces] }
  end

  super(options).tap do |node|
    add_namespace_definitions!(node, self.class.namespace_defs) unless options[:show_definition] == false
  end
end