ensure_subdomain 1.0.1 → 1.0.2

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: 3a5b38bc301b07a5d51159dfc71595fb49e1a919
4
- data.tar.gz: cf9297a48daaa005a972a1e80003b553d78ba4b0
3
+ metadata.gz: ccd1b4114ecac9dc8ae497064e242726a558ddb4
4
+ data.tar.gz: 95b1c2939531da295e2cdeff6d0b7ee857110ba6
5
5
  SHA512:
6
- metadata.gz: 097c68036be7e3c157399be5db6e3f5db1f3e938f4233debdcfd6b284af229634fe4e8e8fc6e1a481c888a0090d206123a5953d6d12d84b27c4f8d318f882fc4
7
- data.tar.gz: 548b8d69cee9fe45c209e97d4edf8a077f50076a5e1eda1b584d1048ebca969a2e6a1d9189ddd7821ba7da1eb5e147fd5b8667ab4ab18af0af21396d6da2d163
6
+ metadata.gz: 5bdc5bee8f1883666e0d786e285b989c8783e925f7f81512b8c359674abe23b99c436c63e8c45daee146893c3746bf2ea35db08f02e785bb242a5e2ef7c1b539
7
+ data.tar.gz: 98a715b2ad1d052f25a97ab0a8ed79e7115efac88fde1a92495cb98b297f36fba23dd0696d011ebe690460f60d9535c43e3f45c4c4d91224c9d5bb5dfa1acad5
data/README.md CHANGED
@@ -1,41 +1,68 @@
1
- # ensure_subdomain
1
+ # Ensure Subdomain
2
2
 
3
- an ActionDispatch extension to handle subdomain redirects
3
+ _an ActionDispatch extension to handle subdomain redirects_
4
4
 
5
5
  Let's say you believe that [using the www subdomain is dumb](http://no-www.org).
6
+
6
7
  Ensuring your rails app doesn't use this subdomain is pretty easy, but now it's easier.
7
8
 
8
- # Gemfile
9
- gem 'ensure_subdomain'
10
-
11
- # Preferred terminal
12
- `bundle install`
13
-
14
- # config/routes.rb
15
- My::Application.routes.draw do
16
- ensure_no_www
17
-
18
- # The rest of my cool routes
19
- end
20
-
21
- GETting http://www.my-app.dev/ will redirect to http://my-app.dev
9
+ ```ruby
10
+ # Gemfile
11
+ gem 'ensure_subdomain'
12
+
13
+ # Preferred terminal
14
+ `bundle install`
15
+
16
+ # config/routes.rb
17
+ Rails.application.routes.draw do
18
+ ensure_apex # or ensure_no_www or ensure_non_www
19
+
20
+ # The rest of my cool routes
21
+ end
22
+ ```
23
+
24
+ GET www.example.com → 301 example.com
25
+
22
26
  Simple as that.
23
27
 
24
28
  Conversely, if you are wrong and think you should use www, there's a method for that.
25
29
 
26
- # config/routes.rb
27
- My::Application.routes.draw do
28
- ensure_www
29
- end
30
+ ```ruby
31
+ # config/routes.rb
32
+ Rails.application.routes.draw do
33
+ ensure_www
34
+ end
35
+ ```
36
+
37
+ GET example.com → 301 www.example.com
38
+
39
+
40
+ If you've got some other domain, there's a method for that too.
41
+
42
+ ```ruby
43
+ # config/routes.rb
44
+ Rails.application.routes.draw do
45
+ ensure_subdomain 'blog'
46
+ end
47
+ ```
48
+
49
+ GET example.com → 301 blog.example.com
50
+
51
+ GET www.example.com → 301 blog.example.com
52
+
53
+ What if you want to control the direction for different environments? I've got ya.
30
54
 
31
- GETting http://www.my-app.dev/ will redirect to http://my-app.dev
55
+ ```ruby
56
+ # config/routes.rb
57
+ Rails.application.routes.draw do
58
+ ensure_on production: 'www',
59
+ staging: 'staging',
60
+ development: 'dev'
61
+ end
62
+ ```
32
63
 
64
+ Also recently added, and somewhat experimental, _not fucking up on Heroku!_
33
65
 
34
- Finally, if you've got some other domain, there's a method for that too.
66
+ *Before:* GET application.herokuapp.com → 301 herokuapp.com → 301 heroku.com
35
67
 
36
- # config/routes.rb
37
- My::Application.routes.draw do
38
- ensure_subdomain 'blog'
39
- end
40
-
41
- GETting http://my-app.dev/ will redirect to http://blog.my-app.dev
68
+ *After:* GET application.herokuapp.com
@@ -31,11 +31,20 @@ module ActionDispatch::Routing::Mapper::HttpHelpers
31
31
  ensure_subdomain ''
32
32
  end
33
33
  alias_method :ensure_non_www, :ensure_no_www
34
+ alias_method :ensure_apex, :ensure_no_www
34
35
 
35
36
  def ensure_www
36
37
  ensure_subdomain 'www'
37
38
  end
38
39
 
40
+ def ensure_on(environments)
41
+ environments.each_pair do |env, domain|
42
+ if Rails.env.to_sym == env
43
+ ensure_subdomain domain
44
+ end
45
+ end
46
+ end
47
+
39
48
  def ensure_subdomain(subdomain, options={})
40
49
  redirector = EnsureSubdomain.new( subdomain )
41
50
  verbs = options[:via] || [:get, :post, :put, :patch, :delete]
@@ -1,9 +1,9 @@
1
1
  class EnsureSubdomain
2
- module VERSION
3
- MAJOR = 1
4
- MINOR = 0
5
- TINY = 1
2
+ module VERSION
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 2
6
6
 
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensure_subdomain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Evan Shreve