Class: ActiveRecord::XmlSerializer

Inherits:
Object
  • Object
show all
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

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_marginObject

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
    options[:indent] ||= 2
    options[:margin] ||= 0
    builder = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent], :margin => options[:margin])

    unless options[:skip_instruct]
      builder.instruct!
      options[:skip_instruct] = true
    end

    builder
  end
end