Class: Shale::Mapping::XmlBase Private
- Inherits:
-
Object
- Object
- Shale::Mapping::XmlBase
- Defined in:
- lib/shale/mapping/xml_base.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for Mapping XML serialization format
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
private
Return attributes mapping hash.
-
#content ⇒ Symbol
readonly
private
Return content mapping.
-
#default_namespace ⇒ Shale::Mapping::Descriptor::XmlNamespace
readonly
private
Return default namespace.
-
#elements ⇒ Hash
readonly
private
Return elements mapping hash.
Instance Method Summary collapse
-
#finalize! ⇒ Object
private
Set the “finalized” instance variable to true.
-
#finalized? ⇒ truem false
private
Query the “finalized” instance variable.
-
#initialize ⇒ XmlBase
constructor
private
Initialize instance.
- #initialize_dup(other) ⇒ Object private
-
#map_attribute(attribute, to: nil, receiver: nil, using: nil, group: nil, namespace: nil, prefix: nil, render_nil: nil) ⇒ Object
private
Map document’s attribute to object’s attribute.
-
#map_content(to: nil, receiver: nil, using: nil, group: nil, cdata: false) ⇒ Object
private
Map document’s content to object’s attribute.
-
#map_element(element, to: nil, receiver: nil, using: nil, group: nil, namespace: :undefined, prefix: :undefined, cdata: false, render_nil: nil) ⇒ Object
private
Map element to attribute.
-
#namespace(name, prefix) ⇒ Object
private
Set default namespace for root element.
-
#prefixed_root ⇒ String
private
Return prefixed root.
-
#root(value) ⇒ Object
private
Set the name for root element.
-
#unprefixed_root ⇒ String
private
Return unprefixed root.
Constructor Details
#initialize ⇒ XmlBase
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize instance
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/shale/mapping/xml_base.rb', line 62 def initialize super @elements = {} @attributes = {} @content = nil @root = '' @default_namespace = Descriptor::XmlNamespace.new @finalized = false @render_nil_default = false end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return attributes mapping hash
25 26 27 |
# File 'lib/shale/mapping/xml_base.rb', line 25 def attributes @attributes end |
#content ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return content mapping
32 33 34 |
# File 'lib/shale/mapping/xml_base.rb', line 32 def content @content end |
#default_namespace ⇒ Shale::Mapping::Descriptor::XmlNamespace (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return default namespace
39 40 41 |
# File 'lib/shale/mapping/xml_base.rb', line 39 def default_namespace @default_namespace end |
#elements ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return elements mapping hash
18 19 20 |
# File 'lib/shale/mapping/xml_base.rb', line 18 def elements @elements end |
Instance Method Details
#finalize! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set the “finalized” instance variable to true
212 213 214 |
# File 'lib/shale/mapping/xml_base.rb', line 212 def finalize! @finalized = true end |
#finalized? ⇒ truem false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Query the “finalized” instance variable
221 222 223 |
# File 'lib/shale/mapping/xml_base.rb', line 221 def finalized? @finalized end |
#initialize_dup(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
226 227 228 229 230 231 232 233 |
# File 'lib/shale/mapping/xml_base.rb', line 226 def initialize_dup(other) @elements = other.instance_variable_get('@elements').dup @attributes = other.instance_variable_get('@attributes').dup @default_namespace = other.instance_variable_get('@default_namespace').dup @finalized = false super end |
#map_attribute(attribute, to: nil, receiver: nil, using: nil, group: nil, namespace: nil, prefix: nil, render_nil: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Map document’s attribute to object’s attribute
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/shale/mapping/xml_base.rb', line 138 def map_attribute( attribute, to: nil, receiver: nil, using: nil, group: nil, namespace: nil, prefix: nil, render_nil: nil ) Validator.validate_arguments(attribute, to, receiver, using) Validator.validate_namespace(attribute, namespace, prefix) namespaced_attribute = [namespace, attribute].compact.join(':') @attributes[namespaced_attribute] = Descriptor::Xml.new( name: attribute, attribute: to, receiver: receiver, methods: using, namespace: Descriptor::XmlNamespace.new(namespace, prefix), cdata: false, group: group, render_nil: render_nil.nil? ? @render_nil_default : render_nil ) end |
#map_content(to: nil, receiver: nil, using: nil, group: nil, cdata: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Map document’s content to object’s attribute
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/shale/mapping/xml_base.rb', line 174 def map_content(to: nil, receiver: nil, using: nil, group: nil, cdata: false) Validator.validate_arguments('content', to, receiver, using) @content = Descriptor::Xml.new( name: nil, attribute: to, receiver: receiver, methods: using, namespace: Descriptor::XmlNamespace.new(nil, nil), cdata: cdata, group: group, render_nil: false ) end |
#map_element(element, to: nil, receiver: nil, using: nil, group: nil, namespace: :undefined, prefix: :undefined, cdata: false, render_nil: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Map element to attribute
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/shale/mapping/xml_base.rb', line 88 def map_element( element, to: nil, receiver: nil, using: nil, group: nil, namespace: :undefined, prefix: :undefined, cdata: false, render_nil: nil ) Validator.validate_arguments(element, to, receiver, using) Validator.validate_namespace(element, namespace, prefix) if namespace == :undefined && prefix == :undefined nsp = default_namespace.name pfx = default_namespace.prefix else nsp = namespace pfx = prefix end namespaced_element = [nsp, element].compact.join(':') @elements[namespaced_element] = Descriptor::Xml.new( name: element, attribute: to, receiver: receiver, methods: using, group: group, namespace: Descriptor::XmlNamespace.new(nsp, pfx), cdata: cdata, render_nil: render_nil.nil? ? @render_nil_default : render_nil ) end |
#namespace(name, prefix) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set default namespace for root element
204 205 206 207 |
# File 'lib/shale/mapping/xml_base.rb', line 204 def namespace(name, prefix) @default_namespace.name = name @default_namespace.prefix = prefix end |
#prefixed_root ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return prefixed root
55 56 57 |
# File 'lib/shale/mapping/xml_base.rb', line 55 def prefixed_root [default_namespace.prefix, @root].compact.join(':') end |
#root(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set the name for root element
194 195 196 |
# File 'lib/shale/mapping/xml_base.rb', line 194 def root(value) @root = value end |
#unprefixed_root ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return unprefixed root
46 47 48 |
# File 'lib/shale/mapping/xml_base.rb', line 46 def unprefixed_root @root end |