Module: Itext::Attachments

Included in:
Itext
Defined in:
lib/itext/attachments.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/itext/attachments.rb', line 9

def self.included(base)
  base.extend(ClassMethods)
  attr_reader :attachments

  # base.class_eval do    
  #   original_method = instance_method(:initialize)
  #   define_method(:initialize) do |*args, &block|
  #     original_method.bind(self).call(*args, &block)
  #     @hooks.push ->{ process_attachments }
  #   end
  # end
end

Instance Method Details

#add_attachments(attachments) ⇒ Object Also known as: add_attachment



22
23
24
25
26
27
28
29
30
31
# File 'lib/itext/attachments.rb', line 22

def add_attachments(attachments)
  @attachments ||= []
  attachments = [attachments] unless attachments.is_a?(Array)
  attachments.each do |attachment|
    if File.exists?(attachment)
      @attachments << attachment
    end
  end
  @attachments
end

#initialize(*args, &block) ⇒ Object



4
5
6
7
# File 'lib/itext/attachments.rb', line 4

def initialize(*args, &block)
  @hooks     ||= []
  @hooks.push ->{ process_attachments }
end

#remove_attachments(attachments) ⇒ Object Also known as: remove_attachment



35
36
37
38
39
40
41
42
43
44
# File 'lib/itext/attachments.rb', line 35

def remove_attachments(attachments)
  @attachments ||= []
  attachments = [attachments] unless attachments.is_a?(Array)
  attachments.each do |attachment|
    if File.exists?(attachment)
      @attachments.delete(attachment)
    end
  end
  @attachments
end