Skip to content

Commit 96f290e

Browse files
committed
Update actionmailer with new hash syntax.
1 parent 918f703 commit 96f290e

15 files changed

+169
-169
lines changed

actionmailer/Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require 'rake/packagetask'
33
require 'rubygems/package_task'
44

55
desc "Default Task"
6-
task :default => [ :test ]
6+
task default: [ :test ]
77

88
# Run the unit tests
99
Rake::TestTask.new { |t|
@@ -29,7 +29,7 @@ Gem::PackageTask.new(spec) do |p|
2929
end
3030

3131
desc "Release to gemcutter"
32-
task :release => :package do
32+
task release: :package do
3333
require 'rake/gemcutter'
3434
Rake::Gemcutter::Tasks.new(spec).define
3535
Rake::Task['gem:push'].invoke

actionmailer/lib/action_mailer/base.rb

+42-42
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ module ActionMailer
2323
# Examples:
2424
#
2525
# class Notifier < ActionMailer::Base
26-
# default :from => '[email protected]',
27-
# :return_path => '[email protected]'
26+
# default from: '[email protected]',
27+
# return_path: '[email protected]'
2828
#
2929
# def welcome(recipient)
3030
# @account = recipient
31-
# mail(:to => recipient.email_address_with_name,
32-
# :bcc => ["[email protected]", "Order Watcher <[email protected]>"])
31+
# mail(to: recipient.email_address_with_name,
32+
# bcc: ["[email protected]", "Order Watcher <[email protected]>"])
3333
# end
3434
# end
3535
#
@@ -62,21 +62,21 @@ module ActionMailer
6262
#
6363
# If you want to explicitly render only certain templates, pass a block:
6464
#
65-
# mail(:to => user.email) do |format|
65+
# mail(to: user.email) do |format|
6666
# format.text
6767
# format.html
6868
# end
6969
#
7070
# The block syntax is also useful in providing information specific to a part:
7171
#
72-
# mail(:to => user.email) do |format|
72+
# mail(to: user.email) do |format|
7373
# format.text(:content_transfer_encoding => "base64")
7474
# format.html
7575
# end
7676
#
7777
# Or even to render a special view:
7878
#
79-
# mail(:to => user.email) do |format|
79+
# mail(to: user.email) do |format|
8080
# format.text
8181
# format.html { render "some_other_template" }
8282
# end
@@ -100,12 +100,12 @@ module ActionMailer
100100
# You can even use Action Pack helpers in these views. For example:
101101
#
102102
# You got a new note!
103-
# <%= truncate(@note.body, :length => 25) %>
103+
# <%= truncate(@note.body, length: 25) %>
104104
#
105105
# If you need to access the subject, from or the recipients in the view, you can do that through message object:
106106
#
107107
# You got a new note from <%= message.from %>!
108-
# <%= truncate(@note.body, :length => 25) %>
108+
# <%= truncate(@note.body, length: 25) %>
109109
#
110110
#
111111
# = Generating URLs
@@ -116,11 +116,11 @@ module ActionMailer
116116
#
117117
# When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
118118
#
119-
# <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
119+
# <%= url_for(host: "example.com", controller: "welcome", action: "greeting") %>
120120
#
121121
# When using named routes you only need to supply the <tt>:host</tt>:
122122
#
123-
# <%= users_url(:host => "example.com") %>
123+
# <%= users_url(host: "example.com") %>
124124
#
125125
# You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the
126126
# <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will
@@ -176,7 +176,7 @@ module ActionMailer
176176
# class ApplicationMailer < ActionMailer::Base
177177
# def welcome(recipient)
178178
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
179-
# mail(:to => recipient, :subject => "New account information")
179+
# mail(to: recipient, subject: "New account information")
180180
# end
181181
# end
182182
#
@@ -192,7 +192,7 @@ module ActionMailer
192192
# class ApplicationMailer < ActionMailer::Base
193193
# def welcome(recipient)
194194
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
195-
# mail(:to => recipient, :subject => "New account information", :body => "")
195+
# mail(to: recipient, subject: "New account information", body: "")
196196
# end
197197
# end
198198
#
@@ -204,7 +204,7 @@ module ActionMailer
204204
# class ApplicationMailer < ActionMailer::Base
205205
# def welcome(recipient)
206206
# attachments.inline['photo.png'] = File.read('path/to/photo.png')
207-
# mail(:to => recipient, :subject => "Here is what we look like")
207+
# mail(to: recipient, subject: "Here is what we look like")
208208
# end
209209
# end
210210
#
@@ -220,7 +220,7 @@ module ActionMailer
220220
#
221221
# <h1>Please Don't Cringe</h1>
222222
#
223-
# <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
223+
# <%= image_tag attachments['photo.png'].url, alt: 'Our Photo', class: 'photo' -%>
224224
#
225225
# = Observing and Intercepting Mails
226226
#
@@ -241,7 +241,7 @@ module ActionMailer
241241
# default method inside the class definition:
242242
#
243243
# class Notifier < ActionMailer::Base
244-
# default :sender => '[email protected]'
244+
# default sender: '[email protected]'
245245
# end
246246
#
247247
# You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box,
@@ -260,7 +260,7 @@ module ActionMailer
260260
#
261261
# class Notifier < ActionMailer::Base
262262
# default 'Content-Transfer-Encoding' => '7bit',
263-
# :content_description => 'This is a description'
263+
# content_description: 'This is a description'
264264
# end
265265
#
266266
# Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
@@ -386,10 +386,10 @@ class Base < AbstractController::Base
386386

387387
class_attribute :default_params
388388
self.default_params = {
389-
:mime_version => "1.0",
390-
:charset => "UTF-8",
391-
:content_type => "text/plain",
392-
:parts_order => [ "text/plain", "text/enriched", "text/html" ]
389+
mime_version: "1.0",
390+
charset: "UTF-8",
391+
content_type: "text/plain",
392+
parts_order: [ "text/plain", "text/enriched", "text/html" ]
393393
}.freeze
394394

395395
class_attribute :queue
@@ -549,17 +549,17 @@ def headers(args=nil)
549549
#
550550
# You can also specify overrides if you want by passing a hash instead of a string:
551551
#
552-
# mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
553-
# :content => File.read('/path/to/filename.jpg')}
552+
# mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
553+
# content: File.read('/path/to/filename.jpg')}
554554
#
555555
# If you want to use a different encoding than Base64, you can pass an encoding in,
556556
# but then it is up to you to pass in the content pre-encoded, and don't expect
557557
# Mail to know how to decode this data:
558558
#
559559
# file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
560-
# mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
561-
# :encoding => 'SpecialEncoding',
562-
# :content => file_content }
560+
# mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
561+
# encoding: 'SpecialEncoding',
562+
# content: file_content }
563563
#
564564
# You can also search for specific attachments:
565565
#
@@ -597,9 +597,9 @@ def attachments
597597
# class method:
598598
#
599599
# class Notifier < ActionMailer::Base
600-
# self.default :from => '[email protected]',
601-
# :bcc => '[email protected]',
602-
# :reply_to => '[email protected]'
600+
# self.default from: '[email protected]',
601+
602+
# reply_to: '[email protected]'
603603
# end
604604
#
605605
# If you need other headers not listed above, you can either pass them in
@@ -621,10 +621,10 @@ def attachments
621621
# For example:
622622
#
623623
# class Notifier < ActionMailer::Base
624-
# default :from => '[email protected]',
624+
# default from: '[email protected]',
625625
#
626626
# def welcome
627-
# mail(:to => '[email protected]')
627+
# mail(to: '[email protected]')
628628
# end
629629
# end
630630
#
@@ -633,22 +633,22 @@ def attachments
633633
#
634634
# However, those can be customized:
635635
#
636-
# mail(:template_path => 'notifications', :template_name => 'another')
636+
# mail(template_path: 'notifications', template_name: 'another')
637637
#
638638
# And now it will look for all templates at "app/views/notifications" with name "another".
639639
#
640640
# If you do pass a block, you can render specific templates of your choice:
641641
#
642-
# mail(:to => '[email protected]') do |format|
642+
# mail(to: '[email protected]') do |format|
643643
# format.text
644644
# format.html
645645
# end
646646
#
647647
# You can even render text directly without using a template:
648648
#
649-
# mail(:to => '[email protected]') do |format|
650-
# format.text { render :text => "Hello Mikel!" }
651-
# format.html { render :text => "<h1>Hello Mikel!</h1>" }
649+
# mail(to: '[email protected]') do |format|
650+
# format.text { render text: "Hello Mikel!" }
651+
# format.html { render text: "<h1>Hello Mikel!</h1>" }
652652
# end
653653
#
654654
# Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
@@ -657,7 +657,7 @@ def attachments
657657
# The block syntax also allows you to customize the part headers if desired:
658658
#
659659
# mail(:to => '[email protected]') do |format|
660-
# format.text(:content_transfer_encoding => "base64")
660+
# format.text(content_transfer_encoding: "base64")
661661
# format.html
662662
# end
663663
#
@@ -730,7 +730,7 @@ def set_content_type(m, user_content_type, class_default)
730730
# humanized version of the <tt>action_name</tt>.
731731
def default_i18n_subject #:nodoc:
732732
mailer_scope = self.class.mailer_name.tr('/', '.')
733-
I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
733+
I18n.t(:subject, scope: [mailer_scope, action_name], default: action_name.humanize)
734734
end
735735

736736
def collect_responses_and_parts_order(headers) #:nodoc:
@@ -743,8 +743,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
743743
responses = collector.responses
744744
elsif headers[:body]
745745
responses << {
746-
:body => headers.delete(:body),
747-
:content_type => self.class.default[:content_type] || "text/plain"
746+
body: headers.delete(:body),
747+
content_type: self.class.default[:content_type] || "text/plain"
748748
}
749749
else
750750
templates_path = headers.delete(:template_path) || self.class.mailer_name
@@ -754,8 +754,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
754754
self.formats = template.formats
755755

756756
responses << {
757-
:body => render(:template => template),
758-
:content_type => template.type.to_s
757+
body: render(template: template),
758+
content_type: template.type.to_s
759759
}
760760
end
761761
end

actionmailer/lib/action_mailer/collector.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def any(*args, &block)
2121
alias :all :any
2222

2323
def custom(mime, options={})
24-
options.reverse_merge!(:content_type => mime.to_s)
24+
options.reverse_merge!(content_type: mime.to_s)
2525
@context.formats = [mime.to_sym]
2626
options[:body] = block_given? ? yield : @default_render.call
2727
@responses << options

actionmailer/lib/action_mailer/delivery_methods.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ module DeliveryMethods
2020
self.delivery_method = :smtp
2121

2222
add_delivery_method :smtp, Mail::SMTP,
23-
:address => "localhost",
24-
:port => 25,
25-
:domain => 'localhost.localdomain',
26-
:user_name => nil,
27-
:password => nil,
28-
:authentication => nil,
29-
:enable_starttls_auto => true
23+
address: "localhost",
24+
port: 25,
25+
domain: 'localhost.localdomain',
26+
user_name: nil,
27+
password: nil,
28+
authentication: nil,
29+
enable_starttls_auto: true
3030

3131
add_delivery_method :file, Mail::FileDelivery,
32-
:location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
32+
location: defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
3333

3434
add_delivery_method :sendmail, Mail::Sendmail,
35-
:location => '/usr/sbin/sendmail',
36-
:arguments => '-i -t'
35+
location: '/usr/sbin/sendmail',
36+
arguments: '-i -t'
3737

3838
add_delivery_method :test, Mail::TestMailer
3939
end
4040

4141
module ClassMethods
4242
# Provides a list of emails that have been delivered by Mail::TestMailer
43-
delegate :deliveries, :deliveries=, :to => Mail::TestMailer
43+
delegate :deliveries, :deliveries=, to: Mail::TestMailer
4444

4545
# Adds a new delivery method through the given class using the given
4646
# symbol as alias and the default options supplied.

actionmailer/lib/rails/generators/mailer/mailer_generator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Generators
33
class MailerGenerator < NamedBase
44
source_root File.expand_path("../templates", __FILE__)
55

6-
argument :actions, :type => :array, :default => [], :banner => "method method"
6+
argument :actions, type: :array, default: [], banner: "method method"
77
check_class_collision
88

99
def create_mailer_file

actionmailer/test/asset_host_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
class AssetHostMailer < ActionMailer::Base
55
def email_with_asset
6-
mail :to => 'test@localhost',
7-
:subject => 'testing email containing asset path while asset_host is set',
8-
:from => '[email protected]'
6+
mail to: 'test@localhost',
7+
subject: 'testing email containing asset path while asset_host is set',
8+
99
end
1010
end
1111

0 commit comments

Comments
 (0)