Class: MIME::Content::Multipart::Base
Overview
base class for multipart mixed, related, digest etc
Defined Under Namespace
Classes: Parser
Instance Attribute Summary collapse
#parser
Attributes inherited from Media
#content, #ct, #hd, #level, #response
Instance Method Summary
collapse
Constructor Details
#initialize(boundary) ⇒ Base
Returns a new instance of Base.
325
326
327
328
329
330
|
# File 'lib/safrano/multipart.rb', line 325
def initialize(boundary)
@boundary = boundary
@hd = {}
@content_id_references = nil
@parser = Parser.new(self)
end
|
Instance Attribute Details
#boundary ⇒ Object
323
324
325
|
# File 'lib/safrano/multipart.rb', line 323
def boundary
@boundary
end
|
Instance Method Details
#==(other) ⇒ Object
332
333
334
|
# File 'lib/safrano/multipart.rb', line 332
def ==(other)
(@boundary == other.boundary) && (@content == other.content)
end
|
#each_changeset ⇒ Object
336
337
338
339
340
341
342
|
# File 'lib/safrano/multipart.rb', line 336
def each_changeset
return unless @level.zero?
@content.each do |part|
yield part if part.is_a? MIME::Content::Multipart::Base
end
end
|
#get_failed_changeset_response(_xeption) ⇒ Object
402
403
404
405
406
407
408
409
410
|
# File 'lib/safrano/multipart.rb', line 402
def get_failed_changeset_response(_xeption)
@response = MIME::Content::Application::HttpResp.new
@response.status = '400'
@response.content = [{ 'odata.error' =>
{ 'message' =>
'Bad Request: Failed changeset ' } }.to_json]
@response.hd = Safrano::CT_JSON
@response
end
|
#get_mult_resp(full_req) ⇒ Object
371
372
373
374
|
# File 'lib/safrano/multipart.rb', line 371
def get_mult_resp(full_req)
get_response(full_req)
[202, @response.hd, @response.unparse_bodyonly]
end
|
#get_response(full_req) ⇒ Object
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
# File 'lib/safrano/multipart.rb', line 376
def get_response(full_req)
@response = self.class.new(::SecureRandom.uuid)
@response.
if @level == 1
full_req.db.transaction do
begin
@response.content = @content.map { |part| part.get_response(full_req) }
rescue Sequel::Rollback => e
get_failed_changeset_response(e)
raise
end
end
else
@response.content = @content.map { |part| part.get_response(full_req) }
end
@response
end
|
#prepare_content_id_refs ⇒ Object
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
# File 'lib/safrano/multipart.rb', line 344
def prepare_content_id_refs
if @level.zero?
each_changeset(&:prepare_content_id_refs)
elsif @level == 1
@content_id_references = {}
@content.each do |part|
next unless part.is_a? MIME::Content::Application::Http
case part.content.http_method
when 'POST', 'PUT'
if (ctid = part.hd['content-id'])
part.content.content_id = ctid
@content_id_references[ctid] = nil
end
end
part.content.content_id_references = @content_id_references
end
end
end
|
#unparse ⇒ Object
412
413
414
415
416
417
418
419
420
421
|
# File 'lib/safrano/multipart.rb', line 412
def unparse
b = +String.new
b << "#{Safrano::CONTENT_TYPE}: #{@hd[CTT_TYPE_LC]}#{CRLF}"
b << crbdcr = "#{CRLF}--#{@boundary}#{CRLF}"
b << @content.map(&:unparse).join(crbdcr)
b << "#{CRLF}--#{@boundary}--#{CRLF}"
b
end
|
#unparse_bodyonly ⇒ Object
423
424
425
426
427
428
429
430
|
# File 'lib/safrano/multipart.rb', line 423
def unparse_bodyonly
b = +String.new
b << crbdcr = "#{CRLF}--#{@boundary}#{CRLF}"
b << @content.map(&:unparse).join(crbdcr)
b << "#{CRLF}--#{@boundary}--#{CRLF}"
b
end
|