ensure_subdomain 0.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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Jacob Evan Shreve
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ensure_subdomain
2
+ =============
3
+
4
+ an ActionDispatch extension to handle subdomain redirects
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/ensure_subdomain/version', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'ensure_subdomain'
7
+ s.version = EnsureSubdomain::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = %w(Jacob Evan Shreve)
10
+ s.email = %w(jacob@shreve.ly)
11
+ s.summary = 'Ensure requests are going to the right subdomain.'
12
+ s.description = 'Ensure requests are going to the right subdomain to avoid competing with yourself for dem SERPs. Adds a couple methods to ActionDispatch for routes.'
13
+ s.homepage = 'https://github.com/shreve/ensure_subdomain'
14
+ s.license = 'MIT'
15
+
16
+ s.add_dependency 'actionpack', '~>4.0.0'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.require_path = 'lib'
20
+ end
@@ -0,0 +1,51 @@
1
+ module EnsureSubdomain
2
+ class WWW
3
+ def self.matches?(request)
4
+ request.host !~ /^www/
5
+ end
6
+ end
7
+
8
+ class NoWWW
9
+ def self.matches?(request)
10
+ request.subdomain =~ /^.*$/
11
+ end
12
+ end
13
+
14
+ class Custom
15
+ attr_accessor :pattern
16
+
17
+ def initialize(pattern)
18
+ self.pattern = pattern
19
+ end
20
+
21
+ def matches?(request)
22
+ request.subdomain.match(self.pattern).nil?
23
+ end
24
+ end
25
+ end
26
+
27
+ module ActionDispatch::Routing::Mapper::HttpHelpers
28
+ include EnsureSubdomain
29
+
30
+ def ensure_no_www
31
+ constraints( EnsureSubdomain::NoWWW ) do
32
+ get '/', to: redirect { |params, request| "#{request.protocol}#{request.domain}" }
33
+ match '/*path', to: redirect { |params, request| "#{request.protocol}#{request.domain}/#{params[:path]}" }, via: [:get, :post, :put, :patch, :delete]
34
+ end
35
+ end
36
+ alias_method :ensure_non_www, :ensure_no_www
37
+
38
+ def ensure_www
39
+ constraints( EnsureSubdomain::WWW ) do
40
+ get '/', to: redirect { |params, request| "#{request.protocol}www.#{request.domain}" }
41
+ match '/*path', to: redirect { |params, request| "#{request.protocol}www.#{request.domain}/#{params[:path]}" }, via: [:get, :post, :put, :patch, :delete]
42
+ end
43
+ end
44
+
45
+ def ensure_subdomain(*args)
46
+ constraints( EnsureSubdomain::Custom.new( args[0] ) ) do
47
+ get '/', to: redirect { |params, request| "#{request.protocol}#{args[0]}.#{request.domain}" }
48
+ match '/*path', to: redirect { |params, request| "#{request.protocol}#{args[0]}.#{request.domain}/#{params[:path]}" }, via: [:get, :post, :put, :patch, :delete]
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module EnsureSubdomain
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ensure_subdomain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jacob
9
+ - Evan
10
+ - Shreve
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-11-08 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: actionpack
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 4.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: 4.0.0
32
+ description: Ensure requests are going to the right subdomain to avoid competing with
33
+ yourself for dem SERPs. Adds a couple methods to ActionDispatch for routes.
34
+ email:
35
+ - jacob@shreve.ly
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - LICENSE
41
+ - README.md
42
+ - ensure_subdomain.gemspec
43
+ - lib/ensure_subdomain.rb
44
+ - lib/ensure_subdomain/version.rb
45
+ homepage: https://github.com/shreve/ensure_subdomain
46
+ licenses:
47
+ - MIT
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Ensure requests are going to the right subdomain.
70
+ test_files: []