Module: Azure::Storage::File::Serialization

Includes:
Common::Service::Serialization
Defined in:
lib/azure/storage/file/serialization.rb

Class Method Summary collapse

Class Method Details

.directories_and_files_enumeration_results_from_xml(xml) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/azure/storage/file/serialization.rb', line 99

def self.directories_and_files_enumeration_results_from_xml(xml)
  xml = slopify(xml)
  expect_node("EnumerationResults", xml)

  results = enumeration_results_from_xml(xml, Azure::Storage::Common::Service::EnumerationResults.new)

  return results unless (xml > "Entries").any?

  if ((xml > "Entries") > "File").any?
    if xml.Entries.File.count == 0
      results.push(file_from_xml(xml.Entries.File))
    else
      xml.Entries.File.each { |file_node|
        results.push(file_from_xml(file_node))
      }
    end
  end

  if ((xml > "Entries") > "Directory").any?
    if xml.Entries.Directory.count == 0
      results.push(directory_from_xml(xml.Entries.Directory))
    else
      xml.Entries.Directory.each { |directory_node|
        results.push(directory_from_xml(directory_node))
      }
    end
  end

  results
end

.directory_from_headers(headers) ⇒ Object



158
159
160
161
162
163
# File 'lib/azure/storage/file/serialization.rb', line 158

def self.directory_from_headers(headers)
  Directory::Directory.new do |directory|
    directory.properties = directory_properties_from_headers(headers)
    directory. = (headers)
  end
end

.directory_from_xml(xml) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/azure/storage/file/serialization.rb', line 149

def self.directory_from_xml(xml)
  xml = slopify(xml)
  expect_node("Directory", xml)

  Directory::Directory.new do |directory|
    directory.name = xml.Name.text if (xml > "Name").any?
  end
end

.directory_properties_from_headers(headers) ⇒ Object



165
166
167
168
169
170
# File 'lib/azure/storage/file/serialization.rb', line 165

def self.directory_properties_from_headers(headers)
  props = {}
  props[:last_modified] = headers["Last-Modified"]
  props[:etag] = headers["ETag"]
  props
end

.file_from_headers(headers) ⇒ Object



172
173
174
175
176
177
# File 'lib/azure/storage/file/serialization.rb', line 172

def self.file_from_headers(headers)
  File.new do |file|
    file.properties = file_properties_from_headers(headers)
    file. = (headers)
  end
end

.file_from_xml(xml) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/azure/storage/file/serialization.rb', line 130

def self.file_from_xml(xml)
  xml = slopify(xml)
  expect_node("File", xml)

  File.new do |file|
    file.name = xml.Name.text if (xml > "Name").any?
    file.properties = file_properties_from_xml(xml.Properties) if (xml > "Properties").any?
  end
end

.file_properties_from_headers(headers) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/azure/storage/file/serialization.rb', line 179

def self.file_properties_from_headers(headers)
  props = {}

  props[:last_modified] = headers["Last-Modified"]
  props[:etag] = headers["ETag"]
  props[:type] = headers["x-ms-type"]

  props[:content_length] = headers["Content-Length"].to_i unless headers["Content-Length"].nil?
  props[:content_length] = headers["x-ms-content-length"].to_i unless headers["x-ms-content-length"].nil?

  props[:content_type] =  headers["Content-Type"]
  props[:content_encoding] = headers["Content-Encoding"]
  props[:content_language] = headers["Content-Language"]
  props[:content_disposition] = headers["Content-Disposition"]
  props[:content_md5] = headers["x-ms-content-md5"] || headers["Content-MD5"]
  props[:range_md5] = headers["Content-MD5"] if headers["x-ms-content-md5"] && headers["Content-MD5"]
  props[:cache_control] = headers["Cache-Control"]

  props[:copy_id] = headers["x-ms-copy-id"]
  props[:copy_status] = headers["x-ms-copy-status"]
  props[:copy_source] = headers["x-ms-copy-source"]
  props[:copy_progress] = headers["x-ms-copy-progress"]
  props[:copy_completion_time] = headers["x-ms-copy-completion-time"]
  props[:copy_status_description] = headers["x-ms-copy-status-description"]

  props[:accept_ranges] = headers["Accept-Ranges"].to_i if headers["Accept-Ranges"]

  props
end

.file_properties_from_xml(xml) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/azure/storage/file/serialization.rb', line 140

def self.file_properties_from_xml(xml)
  xml = slopify(xml)
  expect_node("Properties", xml)

  props = {}
  props[:content_length] = (xml > "Content-Length").text.to_i if (xml > "Content-Length").any?
  props
end

.quota_from_headers(headers) ⇒ Object



89
90
91
# File 'lib/azure/storage/file/serialization.rb', line 89

def self.quota_from_headers(headers)
  headers["x-ms-share-quota"] ? headers["x-ms-share-quota"].to_i : nil
end

.range_list_from_xml(xml) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/azure/storage/file/serialization.rb', line 209

def self.range_list_from_xml(xml)
  xml = slopify(xml)
  expect_node("Ranges", xml)

  range_list = []
  return range_list unless (xml > "Range").any?

  if xml.Range.count == 0
    range_list.push [xml.Range.Start.text.to_i, xml.Range.End.text.to_i]
  else
    xml.Range.each { |range|
      range_list.push [range.Start.text.to_i, range.End.text.to_i]
    }
  end

  range_list
end

.share_enumeration_results_from_xml(xml) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/azure/storage/file/serialization.rb', line 33

def self.share_enumeration_results_from_xml(xml)
  xml = slopify(xml)
  expect_node("EnumerationResults", xml)

  results = enumeration_results_from_xml(xml, Azure::Storage::Common::Service::EnumerationResults.new)

  return results unless (xml > "Shares").any? && ((xml > "Shares") > "Share").any?

  if xml.Shares.Share.count == 0
    results.push(share_from_xml(xml.Shares.Share))
  else
    xml.Shares.Share.each { |share_node|
      results.push(share_from_xml(share_node))
    }
  end

  results
end

.share_from_headers(headers) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/azure/storage/file/serialization.rb', line 74

def self.share_from_headers(headers)
  Share::Share.new do |share|
    share.properties = share_properties_from_headers(headers)
    share.quota = quota_from_headers(headers)
    share. = (headers)
  end
end

.share_from_xml(xml) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/azure/storage/file/serialization.rb', line 52

def self.share_from_xml(xml)
  xml = slopify(xml)
  expect_node("Share", xml)

  Share::Share.new do |share|
    share.name = xml.Name.text if (xml > "Name").any?
    share.properties = share_properties_from_xml(xml.Properties) if (xml > "Properties").any?
    share. = (xml.Metadata) if (xml > "Metadata").any?
  end
end

.share_properties_from_headers(headers) ⇒ Object



82
83
84
85
86
87
# File 'lib/azure/storage/file/serialization.rb', line 82

def self.share_properties_from_headers(headers)
  props = {}
  props[:last_modified] = headers["Last-Modified"]
  props[:etag] = headers["ETag"]
  props
end

.share_properties_from_xml(xml) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/azure/storage/file/serialization.rb', line 63

def self.share_properties_from_xml(xml)
  xml = slopify(xml)
  expect_node("Properties", xml)

  props = {}
  props[:last_modified] = (xml > "Last-Modified").text if (xml > "Last-Modified").any?
  props[:etag] = xml.ETag.text if (xml > "ETag").any?
  props[:quota] = xml.Quota.text if (xml > "Quota").any?
  props
end

.share_stats_from_xml(xml) ⇒ Object



93
94
95
96
97
# File 'lib/azure/storage/file/serialization.rb', line 93

def self.share_stats_from_xml(xml)
  xml = slopify(xml)
  expect_node("ShareStats", xml)
  xml.ShareUsage.text.to_i
end