This commit adds support for optional attributes (nil is an allowed value). Without it, HappyMapper will fail with an error similar to: TypeError in '#to_xml Address before(:all)' wrong argument type Float (expected String) if an attribute is defined with a type other than String, but is actually nil, when to_xml is called. The fix is pretty simple - always calling to_s on the value is the right thing to do for an attribute, because attributes are always text in XML.
…mespace Set the namespace to false for elements that do not share the same namespace as the class: class Alert include HappyMapper namespace 'http://example.com/ns/alert'; element :severity, String, :namespace => false end
This changes how namespaces are declared from previous versions. Instead of declaring the namespace prefix in the mapping, you must declare the namespace URL. class Foo include HappyMapper namespace http://example.com/v2 end
…worry about class definition order (this was all for technicalpickles, enjoy!)
…e issues. Setting the node to nil should be sufficient to mark it for garbage collection, which will run before the ruby program terminates. Signed-off-by: John Nunemaker <firstname.lastname@example.org>
Signed-off-by: John Nunemaker <email@example.com>
When the :parser option is provided for an element mapping along with a non-primitive type, HappyMapper will attempt to coerce the value of the mapped node into the specified type by using the class method specified by :parser. If coercion requires access to the full node (including tags), use :raw => true to parse the full node instead of just the value. Signed-off-by: John Nunemaker <firstname.lastname@example.org>
Attaching a namespace to an instance of an object causes it to be stateful, resulting in non-deterministic behavior when run against different documents in varying orders. When choosing a namespace to use, the order is: 1 - via namespace in class defn 2 - via :namespace in element defn This patch also removes some unnecessary initialization. Signed-off-by: John Nunemaker <email@example.com>
The previous namespace support did not handle documents containing multiply namespaced nodes. It also made assumptions about the 'default' namespace when multiple prefixed namespaces were provided (with no implicit default). This patch allows namespaces to be set item-wide (via 'namespace <ns>' in the class) or on a per-element basis (via :namespace => <ns> on the element mapping). Signed-off-by: John Nunemaker <firstname.lastname@example.org>
…e root element, which sets xpath to use / and sets single to true for this object.
…arting this and providing me with a lot of research.