Class: Mail::PartsList

Inherits:
Array
  • Object
show all
Defined in:
lib/mail/parts_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PartsList

Returns a new instance of PartsList



8
9
10
11
# File 'lib/mail/parts_list.rb', line 8

def initialize(*args)
  @parts = Array.new(*args)
  super @parts
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts



6
7
8
# File 'lib/mail/parts_list.rb', line 6

def parts
  @parts
end

Instance Method Details

#attachmentsObject



24
25
26
# File 'lib/mail/parts_list.rb', line 24

def attachments
  Mail::AttachmentsList.new(@parts)
end

#collectObject Also known as: map



28
29
30
31
32
33
34
35
36
# File 'lib/mail/parts_list.rb', line 28

def collect
  if block_given?
    ary = PartsList.new
    each { |o| ary << yield(o) }
    ary
  else
    to_a
  end
end

#collect!Object

Raises:

  • (NoMethodError)


43
44
45
# File 'lib/mail/parts_list.rb', line 43

def collect!
  raise NoMethodError, "#collect! is not defined, please call #collect and create a new PartsList"
end

#encode_with(coder) ⇒ Object

The #encode_with and #to_yaml methods are just implemented for the sake of backward compatibility ; the delegator does not correctly delegate these calls to the delegated object



16
17
18
# File 'lib/mail/parts_list.rb', line 16

def encode_with(coder) # :nodoc:
  coder.represent_object(nil, @parts)
end

#map!Object

Raises:

  • (NoMethodError)


39
40
41
# File 'lib/mail/parts_list.rb', line 39

def map!
  raise NoMethodError, "#map! is not defined, please call #collect and create a new PartsList"
end

#sortObject



47
48
49
# File 'lib/mail/parts_list.rb', line 47

def sort
  self.class.new(@parts.sort)
end

#sort!(order) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mail/parts_list.rb', line 51

def sort!(order)
  # stable sort should be used to maintain the relative order as the parts are added
  i = 0;
  sorted = @parts.sort_by do |a|
    # OK, 10000 is arbitrary... if anyone actually wants to explicitly sort 10000 parts of a
    # single email message... please show me a use case and I'll put more work into this method,
    # in the meantime, it works :)
    get_order_value(a, order) << (i += 1)
  end
  @parts.clear
  sorted.each { |p| @parts << p }
end

#to_yaml(options = {}) ⇒ Object

:nodoc:



20
21
22
# File 'lib/mail/parts_list.rb', line 20

def to_yaml(options = {}) # :nodoc:
  @parts.to_yaml(options)
end