log4r-mail 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,17 +4,17 @@ require "mail"
4
4
 
5
5
  module Log4r
6
6
  class MailOutputter < Log4r::Outputter
7
- VERSION = "0.0.1"
7
+ VERSION = "0.0.2"
8
8
  attr_accessor :host, :port, :from, :to, :subject, :body, :encoding
9
9
  def initialize(_name, hash={})
10
10
  super(_name, hash)
11
- @host = hash[:host] || "localhost"
12
- @port = hash[:port] || 25
13
- @from = hash[:from] || ""
14
- @to = hash[:to] || ""
15
- @subject = hash[:subject] || ""
16
- @body = hash[:body] || ""
17
- @encoding = hash[:encoding] || "UTF-8"
11
+ @host = hash[:host] || hash["host"] || "localhost"
12
+ @port = hash[:port] || hash["port"] || 25
13
+ @from = hash[:from] || hash["from"] || ""
14
+ @to = hash[:to] || hash["to"] || ""
15
+ @subject = hash[:subject] || hash["subject"] || ""
16
+ @body = hash[:body] || hash["body"] || ""
17
+ @encoding = hash[:encoding] || hash["encoding"] || "UTF-8"
18
18
  end
19
19
 
20
20
  def write(data)
@@ -26,18 +26,18 @@ module Log4r
26
26
  add_files(mail, params)
27
27
  mail.delivery_method :smtp, {
28
28
  :enable_starttls_auto => false,
29
- :address => params[:host] || @host,
30
- :port => params[:port] || @port,
29
+ :address => params[:host] || params["host"] || @host,
30
+ :port => params[:port] || params["port"] || @port.to_i,
31
31
  }
32
32
  mail.deliver
33
33
  end
34
34
 
35
35
  def make_mail(params)
36
- encoding = params[:encoding] || @encoding
37
- from = params[:from] || @from
38
- to = params[:to] || @to
39
- subject = apply_encoding(encoding, params[:subject] || @subject)
40
- body = apply_encoding(encoding, params[:body] || @body)
36
+ encoding = params[:encoding] || params["encoding"] || @encoding
37
+ from = params[:from] || params["from"] || @from
38
+ to = params[:to] || params["to"] || @to
39
+ subject = apply_encoding(encoding, params[:subject] || params["subject"] || @subject)
40
+ body = apply_encoding(encoding, params[:body] || params["body"] || @body)
41
41
 
42
42
  mail = ::Mail.new do
43
43
  from from
@@ -50,8 +50,9 @@ module Log4r
50
50
  end
51
51
 
52
52
  def add_files(mail, params)
53
- return if !params[:files]
54
- params[:files].each do |file|
53
+ files = params[:files] || params["files"]
54
+ return if !files
55
+ files.each do |file|
55
56
  mail.add_file(file)
56
57
  end
57
58
  end
@@ -30,6 +30,25 @@ describe Log4r::MailOutputter do
30
30
  obj.encoding.should == "ISO-2022-JP"
31
31
  end
32
32
 
33
+ it "initialize with hash str key" do
34
+ obj = Log4r::MailOutputter.new("name", {
35
+ "host" => "192.168.0.1",
36
+ "port" => 26,
37
+ "from" => "from@example.com",
38
+ "to" => "to@example.com",
39
+ "subject" => "hello",
40
+ "body" => "world",
41
+ "encoding" => "ISO-2022-JP",
42
+ })
43
+ obj.host.should == "192.168.0.1"
44
+ obj.port.should == 26
45
+ obj.from.should == "from@example.com"
46
+ obj.to.should == "to@example.com"
47
+ obj.subject.should == "hello"
48
+ obj.body.should == "world"
49
+ obj.encoding.should == "ISO-2022-JP"
50
+ end
51
+
33
52
  it "write" do
34
53
  obj = Log4r::MailOutputter.new("name", {
35
54
  from: "from@example.com",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log4r-mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log4r
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  segments:
76
76
  - 0
77
- hash: 3317884028879765247
77
+ hash: -3692594376885376363
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  none: false
80
80
  requirements:
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  segments:
85
85
  - 0
86
- hash: 3317884028879765247
86
+ hash: -3692594376885376363
87
87
  requirements: []
88
88
  rubyforge_project:
89
89
  rubygems_version: 1.8.24