Class: ActiveRecord::XmlSerializer
- Inherits:
-
Object
- Object
- ActiveRecord::XmlSerializer
- Defined in:
- lib/xml_serializer_dumper_support.rb
Overview
Add support to ActiveRecord::XmlSerializer to have value based tags
Defined Under Namespace
Classes: ValueAttribute
Instance Method Summary collapse
-
#add_tag_for_value(name, value) ⇒ Object
Adds a tag based on the name and value and the serializer options Decorations for the tag are derived from the value type.
-
#builder_with_margin ⇒ Object
Add ability to set margin with options to serializer.
Instance Method Details
#add_tag_for_value(name, value) ⇒ Object
Adds a tag based on the name and value and the serializer options Decorations for the tag are derived from the value type
add_tag_for_value('my_tag', "some data")
# XML: <my-tag>some data</my-tag>
26 27 28 |
# File 'lib/xml_serializer_dumper_support.rb', line 26 def add_tag_for_value(name, value) add_tag(ValueAttribute.new(name, @record, value)) end |
#builder_with_margin ⇒ Object
Add ability to set margin with options to serializer
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/xml_serializer_dumper_support.rb', line 4 def builder_with_margin#:nodoc: @builder ||= begin [:indent] ||= 2 [:margin] ||= 0 builder = [:builder] ||= Builder::XmlMarkup.new(:indent => [:indent], :margin => [:margin]) unless [:skip_instruct] builder.instruct! [:skip_instruct] = true end builder end end |