123456789_123456789_123456789_123456789_123456789_

Class: Net::IMAP::Literal

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/net/imap/command_data.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(_data = nil, _non_sync = nil, data: _data, non_sync: _non_sync) ⇒ Literal Also known as: .[]

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 334

def new(_data = nil, _non_sync = nil, data: _data, non_sync: _non_sync)
  super(data: data, non_sync: non_sync)
end

#initialize(data:, non_sync: nil) ⇒ Literal

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 346

def initialize(data:, non_sync: nil)
  data = -String(data.to_str).b or
    raise DataFormatError, "#{self.class} expects string input"
  @data, @non_sync = data, non_sync
  validate
  freeze
end

Class Method Details

.[](_data = nil, _non_sync = nil, data: _data, non_sync: _non_sync)

Alias for .new.

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 337

alias :[] :new

.validate

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 354

def self.validate(...)
  data = new(...)
  data.validate
  data
end

Instance Attribute Details

#data (readonly)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 340

attr_reader :data, :non_sync

#non_sync (readonly)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 340

attr_reader :data, :non_sync

Instance Method Details

#==(other)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 343

def ==(other)   self.class === other && to_h  ==  other.to_h  end

#bytesize

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 360

def bytesize; data.bytesize end

#eql?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 344

def eql?(other) self.class === other && to_h.eql?(other.to_h) end

#send_data(imap, tag)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 369

def send_data(imap, tag)
  imap.__send__(:send_literal, data, tag, non_sync: non_sync)
end

#to_h(&block)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 342

def to_h(&block) block ? to_h.to_h(&block) : { data: data, non_sync: non_sync } end

#validate

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 362

def validate
  if data.include?("\0")
    raise DataFormatError, "NULL byte not allowed in #{self.class}.  " \
      "Use #{Literal8} or a null-safe encoding."
  end
end