Class: ActiveModel::Serializers::Xml::Serializer
- Inherits:
-
Object
- Object
- ActiveModel::Serializers::Xml::Serializer
- Defined in:
- lib/active_model/serializers/xml.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Attribute, MethodAttribute
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(serializable, options = nil) ⇒ Serializer
constructor
A new instance of Serializer.
- #serializable_collection ⇒ Object
- #serializable_hash ⇒ Object
- #serialize ⇒ Object
Constructor Details
#initialize(serializable, options = nil) ⇒ Serializer
Returns a new instance of Serializer.
49 50 51 52 |
# File 'lib/active_model/serializers/xml.rb', line 49 def initialize(serializable, = nil) @serializable = serializable @options = ? .dup : {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
47 48 49 |
# File 'lib/active_model/serializers/xml.rb', line 47 def @options end |
Instance Method Details
#serializable_collection ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/active_model/serializers/xml.rb', line 58 def serializable_collection methods = Array.wrap([:methods]).map(&:to_s) serializable_hash.map do |name, value| name = name.to_s if methods.include?(name) self.class::MethodAttribute.new(name, @serializable, value) else self.class::Attribute.new(name, @serializable, value) end end end |
#serializable_hash ⇒ Object
54 55 56 |
# File 'lib/active_model/serializers/xml.rb', line 54 def serializable_hash @serializable.serializable_hash(@options.except(:include)) end |
#serialize ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/active_model/serializers/xml.rb', line 70 def serialize require 'builder' unless defined? ::Builder [:indent] ||= 2 [:builder] ||= ::Builder::XmlMarkup.new(:indent => [:indent]) @builder = [:builder] @builder.instruct! unless [:skip_instruct] root = ([:root] || @serializable.class.model_name.element).to_s root = ActiveSupport::XmlMini.rename_key(root, ) args = [root] args << {:xmlns => [:namespace]} if [:namespace] args << {:type => [:type]} if [:type] && ![:skip_types] @builder.tag!(*args) do add_attributes_and_methods add_includes add_extra_behavior add_procs yield @builder if block_given? end end |