actionmailer_host_autoset 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +21 -0
- data/README.rdoc +54 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/actionmailer_host_autoset.gemspec +50 -0
- data/lib/actionmailer_host_autoset.rb +4 -0
- data/lib/actionmailer_host_autoset/actionmailer_host_autoset.rb +45 -0
- data/test/actionmailer_host_autoset_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +67 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2007 Nick Kallen
|
2
|
+
Copyright (c) 2009 Tobias Crawley
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= actionmailer_host_autoset
|
2
|
+
|
3
|
+
It is difficult to generate URLs with ActionMailer. Although you can generate
|
4
|
+
absolute paths from your routes, you usually need to generate full URLs for
|
5
|
+
the links in the email to be useful to your recipients.
|
6
|
+
|
7
|
+
This plugin sets the default_url_options for host, port and protocol by
|
8
|
+
providing an around_filter which will grab the values from the request object.
|
9
|
+
In the cases when the request object is not available, for example, when
|
10
|
+
running tests, default values are set instead.
|
11
|
+
|
12
|
+
This is basically a repackaging of retardase_inhibitor
|
13
|
+
(http://github.com/luke0x/retardase_inhibitor), with more descriptive name and
|
14
|
+
a gemspec that will actually build on github (yay for jeweler!).
|
15
|
+
|
16
|
+
=Installation
|
17
|
+
|
18
|
+
# setup gemcutter, if you haven't already:
|
19
|
+
gem install gemcutter
|
20
|
+
gem tumble
|
21
|
+
|
22
|
+
gem install actioncontroller_host_autoset
|
23
|
+
|
24
|
+
Or, in environment.rb:
|
25
|
+
|
26
|
+
config.gem 'actionmailer_host_autoset', :source => 'http://gems.gemcutter.org'
|
27
|
+
|
28
|
+
Then:
|
29
|
+
|
30
|
+
rake gems:install
|
31
|
+
|
32
|
+
=Usage
|
33
|
+
|
34
|
+
Add the around_filter to the ApplicationController to set the
|
35
|
+
default_url_options for every request.
|
36
|
+
|
37
|
+
class ApplicationController < ActionController::Base
|
38
|
+
around_filter :actionmailer_host_autoset
|
39
|
+
end
|
40
|
+
|
41
|
+
I prefer to add it just around the actions when I know an Observer will kick
|
42
|
+
off an ActionMailer notifier. For example, I have an the filter kick off in
|
43
|
+
my SessionsController#create when I process a user signup.
|
44
|
+
|
45
|
+
class SessionsController < ActionController::Base
|
46
|
+
around_filter :actionmailer_host_autoset, :only => :create
|
47
|
+
def create
|
48
|
+
...
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
== Copyright
|
53
|
+
|
54
|
+
Copyright (c) 2007 Nick Kallen, 2009 Tobias Crawley. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "actionmailer_host_autoset"
|
8
|
+
gem.summary = "Sets :host for url_for calls within ActionMailer. A repackaged and renamed version of http://github.com/luke0x/retardase_inhibitor"
|
9
|
+
gem.email = "tcrawley@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/tobias/actionmailer_host_autoset"
|
11
|
+
gem.authors = ["Tobias Crawley"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "actionmailer_host_autoset #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{actionmailer_host_autoset}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tobias Crawley"]
|
12
|
+
s.date = %q{2009-12-08}
|
13
|
+
s.email = %q{tcrawley@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"actionmailer_host_autoset.gemspec",
|
26
|
+
"lib/actionmailer_host_autoset.rb",
|
27
|
+
"lib/actionmailer_host_autoset/actionmailer_host_autoset.rb",
|
28
|
+
"test/actionmailer_host_autoset_test.rb",
|
29
|
+
"test/test_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/tobias/actionmailer_host_autoset}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{Sets :host for url_for calls within ActionMailer. A repackaged and renamed version of http://github.com/luke0x/retardase_inhibitor}
|
36
|
+
s.test_files = [
|
37
|
+
"test/actionmailer_host_autoset_test.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActionmailerHostAutoset
|
2
|
+
module ActionController
|
3
|
+
def self.included(ac)
|
4
|
+
ac.send(:include, InstanceMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
def actionmailer_host_autoset
|
9
|
+
begin
|
10
|
+
request = self.request
|
11
|
+
::ActionMailer::Base.class_eval do
|
12
|
+
@old_default_url_options = default_url_options.clone
|
13
|
+
default_url_options[:host] = request.host
|
14
|
+
default_url_options[:port] = request.port unless [80, 443].include?(request.port)
|
15
|
+
protocol = /(.*):\/\//.match(request.protocol)[1] if request.protocol.ends_with?("://")
|
16
|
+
default_url_options[:protocol] = protocol
|
17
|
+
end
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
::ActionMailer::Base.class_eval do
|
21
|
+
default_url_options[:host] = @old_default_url_options[:host]
|
22
|
+
default_url_options[:port] = @old_default_url_options[:port] unless @old_default_url_options[:port].nil?
|
23
|
+
default_url_options[:protocol] = @old_default_url_options[:protocol]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ActionMailer
|
31
|
+
def self.included(am)
|
32
|
+
am.send(:include, ::ActionController::UrlWriter)
|
33
|
+
am.class_eval do
|
34
|
+
if ENV['RAILS_ENV'] == 'test'
|
35
|
+
default_url_options[:host] = 'test.host'
|
36
|
+
default_url_options[:protocol] = 'http'
|
37
|
+
else
|
38
|
+
default_url_options[:host] = 'localhost'
|
39
|
+
default_url_options[:protocol] = 'http'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionmailer_host_autoset
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Crawley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-08 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: tcrawley@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- actionmailer_host_autoset.gemspec
|
33
|
+
- lib/actionmailer_host_autoset.rb
|
34
|
+
- lib/actionmailer_host_autoset/actionmailer_host_autoset.rb
|
35
|
+
- test/actionmailer_host_autoset_test.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/tobias/actionmailer_host_autoset
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.5
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Sets :host for url_for calls within ActionMailer. A repackaged and renamed version of http://github.com/luke0x/retardase_inhibitor
|
65
|
+
test_files:
|
66
|
+
- test/actionmailer_host_autoset_test.rb
|
67
|
+
- test/test_helper.rb
|