Class: Reap::AnnounceTask

Inherits:
Task
  • Object
show all
Defined in:
lib/reap/tasks/announce-task.rb

Constant Summary

Constants inherited from Task

Task::DEFAULT_INCLUDE, Task::MUST_EXCLUDE, Task::RUBY

Instance Attribute Summary

Attributes inherited from Task

#config, #section

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Task

#[], inherited, #initialize, #package_name, registry, #ruby, #sh, tasks

Constructor Details

This class inherits a constructor from Reap::Task

Class Method Details

.descObject



15
# File 'lib/reap/tasks/announce-task.rb', line 15

def self.desc ; "Sends [ANN] email to ruby-talk or other list." ; end

.taskObject



13
# File 'lib/reap/tasks/announce-task.rb', line 13

def self.task ; :announce ; end

Instance Method Details

#runObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/reap/tasks/announce-task.rb', line 108

def run
  puts "\n#{@message}\n\n"
  print "Send? [Y/n] "
  until inp = $stdin.gets[0,1] ; sleep 1 ; end
  if (inp || 'y').downcase == 'y'
    # ask for password
    print "Password for #{@account}: "
    until passwd = $stdin.gets.strip ; sleep 1 ; end  
    mail = %Q{
     |From: #{@from}
     |To: #{@address}
     |Subject: #{@subject}
     |
     |#{@message}
     }.margin
    begin
      # --- Send using SMTP object and an adaptor
      Net::SMTP.start(@server, @port, @domain, @account, passwd, @authtype) do |s|
        s.send_message mail, @from, @address
      end
      puts "Email sent successfully to #{@address}."
    rescue => e
      puts "Email delivery failed."
      puts e     
    end     
  else
    puts "Reap announce task canceled."
    exit 0
  end
end

#set(section) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/reap/tasks/announce-task.rb', line 18

def set( section )
  @address = section['to']
  @from = section['from'].to_s
  @server = section['server'].to_s.strip
  @port = section['port'] || 25
  @domain = section['domain'].to_s.strip
  @account = section['account'].to_s
  @authtype = section['authtype'].to_sym
  @subject = "[ANN] #{@config['title']}, v#{@config['version']}"

  #raise "DOMAIN is a required field" if @domain.empty?

  announce = %Q{
    |
    |A N N O U N C I N G
    |
    |#{@config['title']}, v#{@config['version']}
    |
    |#{@config['summary']}
    |
    }.margin.center_lines(66)

  # abstract
  abstract = ''
  desc = @config['description']
  if desc
    abstract << "\n\n"
    abstract << "ABSTRACT: #{desc}".word_wrap(72)
    abstract << "\n"
  end

  # more info
  info = ''
  info_arr = section['info']
  unless info_arr.empty?
    info << "\n"
    info << "For More Information".center(67)
    info << "\n"
    info_arr.each{ |mi| info << "#{mi}".center(67) }
    info << "\n\n"
  end

  # slogan
  slogan = ''
  if section['slogan']
    slogan << "\n\n"
    slogan << section['slogan'].center(67)
    slogan << "\n\n"
  end

  # memo
  memo = ''
  if section['memo']
    memo = ''
    memo << "\n" << ('-' * 72) << "\n"
    memo << "(Memo)\n\n"
    memo << section['memo'].clump.word_wrap(72)
    #memo << "\n"
  end

  # msg file
  msg = ''
  msg_file = section['file']
  if msg_file and File.file?( msg_file )
    msg << "\n" << ("-" * 72) << "\n"
    msg << "(from #{msg_file})\n\n"
    mg = ''       
    File.open( msg_file ) { |f| mg << f.gets(nil) }
    msg << mg.clump.word_wrap(72)
  end

  # stamp
  stamp = ''
  stamp << "\n" << ("-" * 72) << "\n"
  stamp << %Q{
    |Generated by Reap, a dedicated Ruby Packaging Assistant.
    |Do you Ruby?  (http://www.ruby-lang.org)
    }.margin
  stamp << "\n\n"
  
  @message = ''
  @message << announce
  @message << abstract
  @message << info
  @message << slogan
  @message << memo
  @message << msg
  @message << stamp      
end