Class: ActiveModel::Serializers::Xml::Serializer
- Inherits:
-
Object
- Object
- ActiveModel::Serializers::Xml::Serializer
- Defined in:
- lib/active_model/serializers/xml.rb
Overview
:nodoc:
Direct Known Subclasses
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.
57 58 59 60 |
# File 'lib/active_model/serializers/xml.rb', line 57 def initialize(serializable, = nil) @serializable = serializable @options = ? .dup : {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
55 56 57 |
# File 'lib/active_model/serializers/xml.rb', line 55 def @options end |
Instance Method Details
#serializable_collection ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_model/serializers/xml.rb', line 66 def serializable_collection methods = Array([: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
62 63 64 |
# File 'lib/active_model/serializers/xml.rb', line 62 def serializable_hash @serializable.serializable_hash(@options.except(:include)) end |
#serialize ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/active_model/serializers/xml.rb', line 78 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.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 |