class MIME::Content::Multipart::Base
base class for multipart mixed, related, digest etc
Attributes
boundary[R]
Public Class Methods
new(boundary)
click to toggle source
# File lib/safrano/multipart.rb, line 326 def initialize(boundary) @boundary = boundary @hd = {} @content_id_references = nil @parser = Parser.new(self) end
Public Instance Methods
==(other)
click to toggle source
# File lib/safrano/multipart.rb, line 333 def ==(other) (@boundary == other.boundary) && (@content == other.content) end
each_changeset() { |part| ... }
click to toggle source
# File lib/safrano/multipart.rb, line 337 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)
click to toggle source
# 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_http_resp(batcha)
click to toggle source
# File lib/safrano/multipart.rb, line 372 def get_http_resp(batcha) get_response(batcha) [@response.hd, @response.unparse(true)] end
get_response(batcha)
click to toggle source
# File lib/safrano/multipart.rb, line 377 def get_response(batcha) @response = self.class.new(::SecureRandom.uuid) @response.set_multipart_header if @level == 1 # changeset need their own global transaction # the change requests that are part of it have @level==2 # and will be flagged with in_changeset=true # and this will finally be used to skip the transaction # of the changes batcha.db.transaction do begin @response.content = @content.map { |part| part.get_response(batcha) } rescue Sequel::Rollback => e # one of the changes of the changeset has failed # --> provide a dummy empty response for the change-parts # then transmit the Rollback to Sequel get_failed_changeset_response(e) raise end end else @response.content = @content.map { |prt| prt.get_response(batcha) } end @response end
prepare_content_id_refs()
click to toggle source
# File lib/safrano/multipart.rb, line 345 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
set_multipart_header()
click to toggle source
# File lib/safrano/multipart.rb, line 368 def set_multipart_header @hd[CTT_TYPE_LC] = "#{Safrano::MP_MIXED}; boundary=#{@boundary}" end
unparse(bodyonly = false)
click to toggle source
# File lib/safrano/multipart.rb, line 412 def unparse(bodyonly = false) b = +String.new unless bodyonly b << "#{Safrano::CONTENT_TYPE}: #{@hd[CTT_TYPE_LC]}#{CRLF}" end b << crbdcr = "#{CRLF}--#{@boundary}#{CRLF}" b << @content.map(&:unparse).join(crbdcr) b << "#{CRLF}--#{@boundary}--#{CRLF}" b end