ensure_domain 1.0.1 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25b4063243441d8631d94a628aad5120d57c7574
4
- data.tar.gz: 6135ccd0f1b4b3c6f1190e285b98837789d251da
3
+ metadata.gz: b8aa693262d01850197cac3e707025b3e43fc6c7
4
+ data.tar.gz: dc75dd2e4a83d2d3cc94037edb466e98382808f3
5
5
  SHA512:
6
- metadata.gz: f92f7231dc0025a3bb2f1e5f35fe836b8ac75b87b375b324a5ec20d8cc1b9dad75d0ce6b864da5a041df13ad3faf7ac066ac1f33af30796a05f5646eae3238bf
7
- data.tar.gz: 13da2170a5dfb032c1bd4bf5d06b5a50ccd854a88033e7126c18cba408d2276b170d6ef3ff183c6759e78cf053b96183756ddebb9ae210448dfab19316e08214
6
+ metadata.gz: 6aea768500ff901e4c125f3f144f3da6633fe34dc3315e7c9e252f7b1476255a987f0d8ab877b3a576cad1407e5c73455a37d7df68ce5e02d0bf7d110077ad30
7
+ data.tar.gz: 16ec215df041eba6c4a40a8c66fe0368e3cdae54cb4ee9aa537e78325ee310fabce7579cc2d6631994d7ba4a48b944b76419ce02802b3f53910ef64857db2c60
data/.gitignore CHANGED
@@ -15,3 +15,8 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Aske Hansen
1
+ Copyright (c) 2014 Aske Hansen
2
2
 
3
3
  MIT License
4
4
 
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # EnsureDomain
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ensure_domain'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ensure_domain
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/ensure_domain/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
+
@@ -8,16 +8,16 @@ Gem::Specification.new do |spec|
8
8
  spec.version = EnsureDomain::VERSION
9
9
  spec.authors = ["Aske Hansen"]
10
10
  spec.email = ["aske@deeco.dk"]
11
- spec.description = "This gem helps your rails app redirect all request to your specified domain"
12
- spec.summary = "Ensures your specific domain"
11
+ spec.summary = "Rack middleware for ensuring domain"
12
+ spec.description = "Rack middleware that will redirect all request that are not from the specified domain"
13
13
  spec.homepage = "https://github.com/askehansen/ensure_domain"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  end
data/lib/ensure_domain.rb CHANGED
@@ -1,17 +1,3 @@
1
1
  require "ensure_domain/version"
2
-
3
- module EnsureDomain
4
- def self.included(base)
5
- base.before_filter :ensure_domain
6
- end
7
-
8
- def ensure_domain
9
- default_url_options = Weboptimist::Application.config.action_mailer.default_url_options
10
- if default_url_options.nil?
11
- puts "WARNING: You must set config.action_mailer.default_url_options = { host: 'www.yourdomain.com' } in order to the 'ensure_domain' gem to work as intended"
12
- elsif Rails.env.production? && request.host != default_url_options[:host]
13
- querystring = "?#{request.query_string}" unless request.query_string.empty?
14
- redirect_to "#{request.protocol}#{default_url_options[:host]}#{request.path}#{querystring}", status: 301
15
- end
16
- end
17
- end
2
+ require "ensure_domain/railtie" if defined?(Rails)
3
+ require "ensure_domain/middleware"
@@ -0,0 +1,29 @@
1
+ module EnsureDomain
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ if ENV['APP_DOMAIN'] && env['HTTP_HOST'] != ENV['APP_DOMAIN']
9
+ [301, {'Location' => new_location(env), 'Content-Type' => 'text/html', 'Content-Length' => '0'}, []]
10
+ else
11
+ @app.call(env)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def new_location(env)
18
+ scheme = env['rack.url_scheme']
19
+ domain = ENV['APP_DOMAIN']
20
+ path = env['PATH_INFO']
21
+ query_string = env['QUERY_STRING'].to_s
22
+
23
+ location = "#{scheme}://#{domain}#{path}"
24
+ location << "?#{query_string}" unless query_string.empty?
25
+
26
+ location
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module EnsureDomain
2
+ class Railtie < Rails::Railtie
3
+ initializer "railtie.configure_rails_initialization" do
4
+ Rails.application.middleware.use EnsureDomain::Middleware
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module EnsureDomain
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,58 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensure_domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aske Hansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-01 00:00:00.000000000 Z
11
+ date: 2014-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: This gem helps your rails app redirect all request to your specified
42
- domain
41
+ description: Rack middleware that will redirect all request that are not from the
42
+ specified domain
43
43
  email:
44
44
  - aske@deeco.dk
45
45
  executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
50
  - Gemfile
51
51
  - LICENSE.txt
52
- - README.rdoc
52
+ - README.md
53
53
  - Rakefile
54
54
  - ensure_domain.gemspec
55
55
  - lib/ensure_domain.rb
56
+ - lib/ensure_domain/middleware.rb
57
+ - lib/ensure_domain/railtie.rb
56
58
  - lib/ensure_domain/version.rb
57
59
  homepage: https://github.com/askehansen/ensure_domain
58
60
  licenses:
@@ -64,18 +66,18 @@ require_paths:
64
66
  - lib
65
67
  required_ruby_version: !ruby/object:Gem::Requirement
66
68
  requirements:
67
- - - '>='
69
+ - - ">="
68
70
  - !ruby/object:Gem::Version
69
71
  version: '0'
70
72
  required_rubygems_version: !ruby/object:Gem::Requirement
71
73
  requirements:
72
- - - '>='
74
+ - - ">="
73
75
  - !ruby/object:Gem::Version
74
76
  version: '0'
75
77
  requirements: []
76
78
  rubyforge_project:
77
- rubygems_version: 2.0.2
79
+ rubygems_version: 2.4.1
78
80
  signing_key:
79
81
  specification_version: 4
80
- summary: Ensures your specific domain
82
+ summary: Rack middleware for ensuring domain
81
83
  test_files: []
data/README.rdoc DELETED
@@ -1,32 +0,0 @@
1
- = EnsureDomain
2
-
3
- This gem helps your rails app redirect all request to your specified domain.
4
-
5
- Example: myhomepage.com => www.myhomepage.com
6
-
7
- == Installation
8
- 1. Add gem in your gemfile:
9
-
10
- gem "ensure_domain"
11
-
12
- 2. include the module in your application_controller.rb file:
13
-
14
- # app/controllers/application_controller.rb
15
-
16
- class ApplicationController < ActionController::Base
17
- include EnsureDomain
18
- end
19
-
20
- 3. Specify your domain in your production.rb file:
21
-
22
- # config/environments/production.rb
23
-
24
- MyApp::Application.configure do
25
- config.action_mailer.default_url_options = { host: "www.myhomepage.com" }
26
- end
27
-
28
- All requests should now redirect to www.myhomepage.com
29
-
30
- == License
31
-
32
- This project rocks and uses MIT-LICENSE.