Module: Azure::Service::Serialization::ClassMethods
- Included in:
- Azure::Service::Serialization
- Defined in:
- lib/azure/service/serialization.rb
Instance Method Summary collapse
- #access_policy_from_xml(xml) ⇒ Object
- #enumeration_results_from_xml(xml, results) ⇒ Object
- #expect_node(node_name, xml) ⇒ Object
- #logging_from_xml(xml) ⇒ Object
- #logging_to_xml(logging, xml) ⇒ Object
- #metadata_from_headers(headers) ⇒ Object
- #metadata_from_xml(xml) ⇒ Object
- #metrics_from_xml(xml) ⇒ Object
- #metrics_to_xml(metrics, xml) ⇒ Object
- #retention_policy_from_xml(xml) ⇒ Object
- #retention_policy_to_xml(retention_policy, xml) ⇒ Object
- #service_properties_from_xml(xml) ⇒ Object
- #service_properties_to_xml(properties) ⇒ Object
- #signed_identifier_from_xml(xml) ⇒ Object
- #signed_identifiers_from_xml(xml) ⇒ Object
- #signed_identifiers_to_xml(signed_identifiers) ⇒ Object
- #slopify(xml) ⇒ Object
- #to_bool(s) ⇒ Object
Instance Method Details
#access_policy_from_xml(xml) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/azure/service/serialization.rb', line 77 def access_policy_from_xml(xml) xml = slopify(xml) expect_node("AccessPolicy", xml) AccessPolicy.new do |policy| policy.start = xml.Start.text if (xml > "Start").any? policy.expiry = xml.Expiry.text if (xml > "Expiry").any? policy. = xml.Permission.text if (xml > "Permission").any? end end |
#enumeration_results_from_xml(xml, results) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/azure/service/serialization.rb', line 88 def enumeration_results_from_xml(xml, results) xml = slopify(xml) expect_node("EnumerationResults", xml) results = results || EnumerationResults.new; results.continuation_token = xml.NextMarker.text if (xml > "NextMarker").any? results end |
#expect_node(node_name, xml) ⇒ Object
228 229 230 |
# File 'lib/azure/service/serialization.rb', line 228 def expect_node(node_name, xml) raise "Xml is not a #{node_name} node." unless xml.name == node_name end |
#logging_from_xml(xml) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/azure/service/serialization.rb', line 182 def logging_from_xml(xml) xml = slopify(xml) expect_node("Logging", xml) Logging.new do |logging| logging.version = xml.Version.text if (xml > "Version").any? logging.delete = to_bool(xml.Delete.text) if (xml > "Delete").any? logging.read = to_bool(xml.Read.text) if (xml > "Read").any? logging.write = to_bool(xml.Write.text) if (xml > "Write").any? logging.retention_policy = retention_policy_from_xml(xml.RetentionPolicy) end end |
#logging_to_xml(logging, xml) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/azure/service/serialization.rb', line 172 def logging_to_xml(logging, xml) xml.Logging { xml.Version logging.version if logging.version xml.Delete logging.delete unless logging.delete == nil xml.Read logging.read unless logging.read == nil xml.Write logging.write unless logging.write == nil retention_policy_to_xml(logging.retention_policy, xml) if logging.retention_policy } end |
#metadata_from_headers(headers) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/azure/service/serialization.rb', line 117 def (headers) = {} headers.each { |k, v| if key = k[/^x-ms-meta-(.*)/, 1] if .has_key? key [key] = [[key]] unless [key].respond_to? :push [key].push(v) else [key] = v end end } end |
#metadata_from_xml(xml) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/azure/service/serialization.rb', line 98 def (xml) xml = slopify(xml) expect_node("Metadata", xml) = {} xml.children.each { || key = .name.downcase if .has_key? key [key] = [[key]] unless [key].respond_to? :push [key].push(.text) else [key] = .text end } end |
#metrics_from_xml(xml) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/azure/service/serialization.rb', line 160 def metrics_from_xml(xml) xml = slopify(xml) expect_node("Metrics", xml) Metrics.new do |metrics| metrics.version = xml.Version.text if (xml > "Version").any? metrics.enabled = to_bool(xml.Enabled.text) if (xml > "Enabled").any? metrics.include_apis = to_bool(xml.IncludeAPIs.text) if (xml > "IncludeAPIs").any? metrics.retention_policy = retention_policy_from_xml(xml.RetentionPolicy) end end |
#metrics_to_xml(metrics, xml) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/azure/service/serialization.rb', line 151 def metrics_to_xml(metrics, xml) xml.Metrics { xml.Version metrics.version if metrics.version xml.Enabled metrics.enabled unless metrics.enabled == nil xml.IncludeAPIs metrics.include_apis unless metrics.include_apis == nil retention_policy_to_xml(metrics.retention_policy, xml) if metrics.retention_policy } end |
#retention_policy_from_xml(xml) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/azure/service/serialization.rb', line 141 def retention_policy_from_xml(xml) xml = slopify(xml) expect_node("RetentionPolicy", xml) RetentionPolicy.new do |policy| policy.enabled = to_bool(xml.Enabled.text) if (xml > "Enabled").any? policy.days = xml.Days.text.to_i if (xml > "Days").any? end end |
#retention_policy_to_xml(retention_policy, xml) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/azure/service/serialization.rb', line 134 def retention_policy_to_xml(retention_policy, xml) xml.RetentionPolicy { xml.Enabled retention_policy.enabled unless retention_policy.enabled == nil xml.Days retention_policy.days if retention_policy.days } end |
#service_properties_from_xml(xml) ⇒ Object
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/azure/service/serialization.rb', line 206 def service_properties_from_xml(xml) xml = slopify(xml) expect_node("StorageServiceProperties", xml) StorageServiceProperties.new do |props| props.default_service_version = xml.DefaultServiceVersion.text if (xml > "DefaultServiceVersion").any? props.logging = logging_from_xml(xml.Logging) props.metrics = metrics_from_xml(xml.Metrics) end end |
#service_properties_to_xml(properties) ⇒ Object
195 196 197 198 199 200 201 202 203 204 |
# File 'lib/azure/service/serialization.rb', line 195 def service_properties_to_xml(properties) builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml| xml.StorageServiceProperties { logging_to_xml(properties.logging, xml) if properties.logging metrics_to_xml(properties.metrics, xml) if properties.metrics xml.DefaultServiceVersion properties.default_service_version if properties.default_service_version } end builder.to_xml end |
#signed_identifier_from_xml(xml) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/azure/service/serialization.rb', line 67 def signed_identifier_from_xml(xml) xml = slopify(xml) expect_node("SignedIdentifier", xml) SignedIdentifier.new do |identifier| identifier.id = xml.Id.text if (xml > "Id").any? identifier.access_policy = access_policy_from_xml(xml.AccessPolicy) if (xml > "AccessPolicy").any? end end |
#signed_identifiers_from_xml(xml) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/azure/service/serialization.rb', line 31 def signed_identifiers_from_xml(xml) xml = slopify(xml) expect_node("SignedIdentifiers", xml) identifiers = [] return identifiers unless (xml > "SignedIdentifier").any? if xml.SignedIdentifier.count == 0 identifiers.push(signed_identifier_from_xml(xml.SignedIdentifier)) else xml.SignedIdentifier.each { |identifier_node| identifiers.push(signed_identifier_from_xml(identifier_node)) } end identifiers end |
#signed_identifiers_to_xml(signed_identifiers) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/azure/service/serialization.rb', line 49 def signed_identifiers_to_xml(signed_identifiers) builder = Nokogiri::XML::Builder.new(:encoding=>"utf-8") do |xml| xml.SignedIdentifiers { signed_identifiers.each do |identifier| xml.SignedIdentifier { xml.Id identifier.id xml.AccessPolicy { xml.Start identifier.access_policy.start xml.Expiry identifier.access_policy.expiry xml.Permission identifier.access_policy. } } end } end builder.to_xml end |
#slopify(xml) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/azure/service/serialization.rb', line 221 def slopify(xml) node = (xml.is_a? String) ? Nokogiri.Slop(xml).root : xml node.slop! if node.is_a? Nokogiri::XML::Document unless node.respond_to? :method_missing node = node.root if node.is_a? Nokogiri::XML::Document node end |
#to_bool(s) ⇒ Object
217 218 219 |
# File 'lib/azure/service/serialization.rb', line 217 def to_bool(s) (s || "").downcase == 'true' end |