Class: MailProcessor::MailDir
- Defined in:
- lib/mail_processor/mail_dir.rb
Instance Method Summary collapse
- #glob(v = nil) ⇒ Object
-
#initialize(options = {}, &block) ⇒ MailDir
constructor
A new instance of MailDir.
- #process(options = {}, &block) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}, &block) ⇒ MailDir
Returns a new instance of MailDir.
9 10 11 12 13 14 15 |
# File 'lib/mail_processor/mail_dir.rb', line 9 def initialize = {}, &block @attributes = { :glob => "#{ENV['HOME']}/MailDir/new/*", } merge_to_attributes() instance_eval &block if block_given? end |
Instance Method Details
#glob(v = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/mail_processor/mail_dir.rb', line 18 def glob v = nil if v @attributes[:glob] = v else @attributes[:glob] end end |
#process(options = {}, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mail_processor/mail_dir.rb', line 27 def process( = {}, &block) a = @attributes.merge() count = 0 Dir.glob(a[ :glob ]) do |filename| yield(File.read_binary(filename)) FileUtils::rm(filename) count += 1 end log.info "Processed #{count} mails" count == 0 end |