pony 1.0.1 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -0
- data/Rakefile +2 -16
- data/lib/pony.rb +25 -2
- data/pony.gemspec +1 -1
- data/spec/base.rb +1 -1
- data/spec/pony_spec.rb +22 -1
- metadata +7 -5
data/README.rdoc
CHANGED
@@ -87,6 +87,14 @@ Other options
|
|
87
87
|
via # :smtp or :sendmail, see Transport section above
|
88
88
|
via_options # specify transport options, see Transport section above
|
89
89
|
|
90
|
+
== Set default options
|
91
|
+
|
92
|
+
Default options can be set so that they don't have to be repeated. The default options you set will be overriden by any options you pass in to Pony.mail()
|
93
|
+
|
94
|
+
Pony.options = { :from => 'noreply@example.com', :via => :smtp, :via_options => { :host => 'smtp.yourserver.com' } }
|
95
|
+
Pony.mail(:to => 'foo@bar') # Sends mail to foo@bar from noreply@example.com using smtp
|
96
|
+
Pony.mail(:from => 'pony@example.com', :to => 'foo@bar') # Sends mail to foo@bar from pony@example.com using smtp
|
97
|
+
|
90
98
|
== Help
|
91
99
|
|
92
100
|
If you need help using Pony, or it looks like you've found a bug, we have a google group setup at: ponyrb@googlegroups.com.
|
@@ -124,6 +132,9 @@ mailing list: ponyrb@googlegroups.com
|
|
124
132
|
|
125
133
|
== Releases
|
126
134
|
|
135
|
+
1.1
|
136
|
+
* Add default options
|
137
|
+
|
127
138
|
1.0
|
128
139
|
* Convert to using Mail as the mail-generation backend, instead of TMail
|
129
140
|
|
data/Rakefile
CHANGED
@@ -1,22 +1,8 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
desc "Run all specs"
|
5
|
-
|
6
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
7
|
-
end
|
8
|
-
|
9
|
-
desc "Print specdocs"
|
10
|
-
Spec::Rake::SpecTask.new(:doc) do |t|
|
11
|
-
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
12
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "Run all examples with RCov"
|
16
|
-
Spec::Rake::SpecTask.new('rcov') do |t|
|
17
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
18
|
-
t.rcov = true
|
19
|
-
t.rcov_opts = ['--exclude', 'examples']
|
5
|
+
RSpec::Core::RakeTask.new() do |t|
|
20
6
|
end
|
21
7
|
|
22
8
|
task :default => :spec
|
data/lib/pony.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'mail'
|
3
3
|
require 'base64'
|
4
4
|
|
5
|
-
# =
|
5
|
+
# = The express way to send email in Ruby
|
6
6
|
#
|
7
7
|
# == Overview
|
8
8
|
#
|
@@ -90,16 +90,39 @@ require 'base64'
|
|
90
90
|
# Other options
|
91
91
|
# via # :smtp or :sendmail, see Transport section above
|
92
92
|
# via_options # specify transport options, see Transport section above
|
93
|
-
|
93
|
+
#
|
94
|
+
# == Set default options
|
95
|
+
#
|
96
|
+
# Default options can be set so that they don't have to be repeated. The default options you set will be overriden by any options you pass in to Pony.mail()
|
97
|
+
#
|
98
|
+
# Pony.options = { :from => 'noreply@example.com', :via => :smtp, :via_options => { :host => 'smtp.yourserver.com' } }
|
99
|
+
# Pony.mail(:to => 'foo@bar') # Sends mail to foo@bar from noreply@example.com using smtp
|
100
|
+
# Pony.mail(:from => 'pony@example.com', :to => 'foo@bar') # Sends mail to foo@bar from pony@example.com using smtp
|
94
101
|
|
95
102
|
|
96
103
|
module Pony
|
97
104
|
|
105
|
+
@@options = {}
|
106
|
+
|
107
|
+
# Default options can be set so that they don't have to be repeated.
|
108
|
+
#
|
109
|
+
# Pony.options = { :from => 'noreply@example.com', :via => :smtp, :via_options => { :host => 'smtp.yourserver.com' } }
|
110
|
+
# Pony.mail(:to => 'foo@bar') # Sends mail to foo@bar from noreply@example.com using smtp
|
111
|
+
# Pony.mail(:from => 'pony@example.com', :to => 'foo@bar') # Sends mail to foo@bar from pony@example.com using smtp
|
112
|
+
def self.options=(value)
|
113
|
+
@@options = value
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.options()
|
117
|
+
@@options
|
118
|
+
end
|
119
|
+
|
98
120
|
# Send an email
|
99
121
|
# Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Hello there.')
|
100
122
|
# Pony.mail(:to => 'you@example.com', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
|
101
123
|
# Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howsit!')
|
102
124
|
def self.mail(options)
|
125
|
+
options = @@options.merge options
|
103
126
|
raise(ArgumentError, ":to is required") unless options[:to]
|
104
127
|
|
105
128
|
options[:via] = default_delivery_method unless options.has_key?(:via)
|
data/pony.gemspec
CHANGED
data/spec/base.rb
CHANGED
data/spec/pony_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe Pony do
|
|
27
27
|
|
28
28
|
it "should handle depricated options gracefully" do
|
29
29
|
Pony.should_receive(:build_mail).with(hash_including(:via_options => {:address => 'test'}))
|
30
|
-
Pony.mail(:to => 'foo@bar', :smtp => { :host => 'test' })
|
30
|
+
Pony.mail(:to => 'foo@bar', :smtp => { :host => 'test' }, :via => :smtp)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should handle depricated content-type gracefully" do
|
@@ -212,4 +212,25 @@ describe Pony do
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
+
describe "default options" do
|
216
|
+
it "should use default options" do
|
217
|
+
Pony.should_receive(:build_mail).with(hash_including(:from => 'noreply@pony'))
|
218
|
+
Pony.options = { :from => 'noreply@pony' }
|
219
|
+
Pony.mail(:to => 'foo@bar')
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should merge default options with options" do
|
223
|
+
Pony.should_receive(:build_mail).with(hash_including(:from => 'override@pony'))
|
224
|
+
Pony.options = { :from => 'noreply@pony' }
|
225
|
+
Pony.mail(:from => 'override@pony', :to => "foo@bar")
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should return the default options" do
|
229
|
+
input = { :from => 'noreply@pony' }
|
230
|
+
Pony.options = input
|
231
|
+
output = Pony.options
|
232
|
+
output.should == input
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
215
236
|
end
|
metadata
CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
version: 1.
|
8
|
+
version: "1.1"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- Adam Wiggins
|
@@ -15,13 +14,14 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-02 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: mail
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
25
|
requirements:
|
26
26
|
- - ">"
|
27
27
|
- !ruby/object:Gem::Version
|
@@ -45,8 +45,8 @@ files:
|
|
45
45
|
- pony.gemspec
|
46
46
|
- lib/pony.rb~
|
47
47
|
- lib/pony.rb
|
48
|
-
- spec/base.rb
|
49
48
|
- spec/pony_spec.rb~
|
49
|
+
- spec/base.rb
|
50
50
|
- spec/pony_spec.rb
|
51
51
|
has_rdoc: true
|
52
52
|
homepage: http://github.com/benprew/pony
|
@@ -59,6 +59,7 @@ rdoc_options:
|
|
59
59
|
require_paths:
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
62
63
|
requirements:
|
63
64
|
- - ">="
|
64
65
|
- !ruby/object:Gem::Version
|
@@ -66,6 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
67
|
- 0
|
67
68
|
version: "0"
|
68
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
69
71
|
requirements:
|
70
72
|
- - ">="
|
71
73
|
- !ruby/object:Gem::Version
|
@@ -75,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
77
|
requirements: []
|
76
78
|
|
77
79
|
rubyforge_project: pony
|
78
|
-
rubygems_version: 1.3.
|
80
|
+
rubygems_version: 1.3.7
|
79
81
|
signing_key:
|
80
82
|
specification_version: 3
|
81
83
|
summary: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|