ensure_subdomain 0.0.3 → 0.9.9

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.
@@ -1,8 +1,8 @@
1
- module EnsureSubdomain
1
+ class EnsureSubdomain
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 3
4
+ MINOR = 9
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,51 +1,38 @@
1
- module EnsureSubdomain
2
- class WWW
3
- def self.matches?(request)
4
- request.host !~ /^www/
5
- end
1
+ class EnsureSubdomain
2
+ attr_accessor :subdomain
3
+
4
+ def initialize(subdomain)
5
+ self.subdomain = subdomain.sub(/\.$/, '')
6
6
  end
7
7
 
8
- class NoWWW
9
- def self.matches?(request)
10
- request.subdomain =~ /^.*$/
11
- end
8
+ def matches?(request)
9
+ request.subdomain.match(self.subdomain).nil?
12
10
  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
11
+
12
+ def to(params, request)
13
+ url = request.protocol
14
+ url << "#{self.subdomain}." if self.subdomain.present?
15
+ url << request.domain
16
+ url << "/#{params[:path]}" if params[:path].present?
17
+ url
24
18
  end
25
19
  end
26
20
 
27
21
  module ActionDispatch::Routing::Mapper::HttpHelpers
28
- include EnsureSubdomain
29
-
30
22
  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
23
+ ensure_subdomain ''
35
24
  end
36
25
  alias_method :ensure_non_www, :ensure_no_www
37
26
 
38
27
  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
28
+ ensure_subdomain 'www'
43
29
  end
44
30
 
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]
31
+ def ensure_subdomain(subdomain, options={})
32
+ redirector = EnsureSubdomain.new( subdomain )
33
+ verbs = options[:via] || [:get, :post, :put, :patch, :delete]
34
+ constraints( redirector ) do
35
+ match '/*path', to: redirect { |params, request| redirector.to params, request }, via: verbs
49
36
  end
50
37
  end
51
38
  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: 0.0.3
4
+ version: 0.9.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-08 00:00:00.000000000 Z
12
+ date: 2013-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -37,7 +37,6 @@ extra_rdoc_files: []
37
37
  files:
38
38
  - LICENSE
39
39
  - README.md
40
- - ensure_subdomain-0.0.2.gem
41
40
  - ensure_subdomain.gemspec
42
41
  - lib/ensure_subdomain.rb
43
42
  - lib/ensure_subdomain/version.rb
Binary file