tobias-actionmailer_host_autoset 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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,38 @@
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 a less terrible name and
14
+ a gemspec that will actually build on github (yay for jeweler!).
15
+
16
+ =Usage
17
+
18
+ Add the around_filter to the ApplicationController to set the
19
+ default_url_options for every request.
20
+
21
+ class ApplicationController < ActionController::Base
22
+ around_filter :actionmailer_host_autoset
23
+ end
24
+
25
+ I prefer to add it just around the actions when I know an Observer will kick
26
+ off an ActionMailer notifier. For example, I have an the filter kick off in
27
+ my SessionsController#create when I process a user signup.
28
+
29
+ class SessionsController < ActionController::Base
30
+ around_filter :actionmailer_host_autoset, :only => :create
31
+ def create
32
+ ...
33
+ end
34
+ end
35
+
36
+ == Copyright
37
+
38
+ 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
+
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.2.1
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{actionmailer_host_autoset}
5
+ s.version = "0.2.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Tobias Crawley"]
9
+ s.date = %q{2009-06-09}
10
+ s.email = %q{tcrawley@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "actionmailer_host_autoset.gemspec",
23
+ "lib/actionmailer_host_autoset.rb",
24
+ "lib/actionmailer_host_autoset/actionmailer_host_autoset.rb",
25
+ "test/actionmailer_host_autoset_test.rb",
26
+ "test/test_helper.rb"
27
+ ]
28
+ s.has_rdoc = true
29
+ s.homepage = %q{http://github.com/tobias/actionmailer_host_autoset}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.1}
33
+ s.summary = %q{Sets :host for url_for calls within ActionMailer. A repackaged and renamed version of http://github.com/luke0x/retardase_inhibitor}
34
+ s.test_files = [
35
+ "test/actionmailer_host_autoset_test.rb",
36
+ "test/test_helper.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 2
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ else
45
+ end
46
+ else
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ require 'actionmailer_host_autoset/actionmailer_host_autoset'
2
+
3
+ ActionController::Base.send(:include, ActionmailerHostAutoset::ActionController)
4
+ ActionMailer::Base.send(:include, ActionmailerHostAutoset::ActionMailer)
@@ -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
+ ::ActionController::UrlWriter.module_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
+ ::ActionController::UrlWriter.module_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
+ ::ActionController::UrlWriter.module_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
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ActionmailerHostAutosetTest < Test::Unit::TestCase
4
+ should "probably have some tests" do
5
+ flunk "but it doesn't!"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'actionmailer_host_autoset'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tobias-actionmailer_host_autoset
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Crawley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-09 00:00:00 -07: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
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Sets :host for url_for calls within ActionMailer. A repackaged and renamed version of http://github.com/luke0x/retardase_inhibitor
63
+ test_files:
64
+ - test/actionmailer_host_autoset_test.rb
65
+ - test/test_helper.rb