forked from kgiszczak/shale
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When a collection is empty, don't render anything #5
Comments
@ronaldtse I tried to run the below code and it does not render anything if the collection is empty. require 'shale'
require 'shale/adapter/nokogiri'
Shale.xml_adapter = Shale::Adapter::Nokogiri
class Address < Shale::Mapper
attribute :city, Shale::Type::String
attribute :street, Shale::Type::String
attribute :zip, Shale::Type::String, collection: true
xml do
root "address"
map_element "city", to: :city
map_element "street", to: :street
map_element "zip", to: :zip
end
end
address = Address.from_xml(<<~DATA)
<address>
<city>London</city>
<street>Oxford Street</street>
</address>
DATA
puts address.to_xml(pretty: true) the above code outputs the following XML <address>
<city>London</city>
<street>Oxford Street</street>
</address> Do you mean something else here? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When a collection is empty, there is no need to render.
Instead, apply
render_nil: true
behavior when specified. Right nowrender_nil
only works on elements not on collections.The text was updated successfully, but these errors were encountered: