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



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

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

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts



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

def parts
  @parts
end

Instance Method Details

#attachmentsObject



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

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

#collectObject Also known as: map



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

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

#collect!Object

Raises:

  • (NoMethodError)


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

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



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

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

#map!Object

Raises:

  • (NoMethodError)


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

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

#sortObject



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

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

#sort!(order) ⇒ Object



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

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:



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

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