submariner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +11 -0
- data/Rakefile +27 -0
- data/lib/rack/wildcard_subdomains.rb +30 -0
- data/lib/submariner.rb +20 -0
- data/lib/submariner/railtie.rb +7 -0
- data/lib/submariner/version.rb +3 -0
- data/lib/tasks/submariner_tasks.rake +4 -0
- metadata +91 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Submariner
|
2
|
+
Easy wildcard subdomains in rails
|
3
|
+
|
4
|
+
Basically this run a block and pass the subdomain to it so you can do interesting things like load a user based on subdomain etc.
|
5
|
+
|
6
|
+
Submariner::WildCardSubdomain.config do |config|
|
7
|
+
config.subdomains_to_ignore = ["www"] #Don't run the block for these domains
|
8
|
+
config.subdomain_block = lambda { |subdomain| Rails.logger.warn "Subdomain block ran for #{subdomain}" } #Do something everytime a domain is detected
|
9
|
+
end
|
10
|
+
|
11
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Submariner'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Rack
|
2
|
+
class WildCardSubdomains
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
#Lets leave it alone if we're in development
|
9
|
+
return @app.call(env) if env["HTTP_HOST"] =~ /127\.0\.0\.1/
|
10
|
+
|
11
|
+
#Move along, nothing to see here, subdomain we should ignore
|
12
|
+
subdomain = nil
|
13
|
+
matches = env["HTTP_HOST"].match(/([^\.]*)\..+\..+/)
|
14
|
+
#Keep going if there isn't a subdomain
|
15
|
+
if matches.nil?
|
16
|
+
Rails.logger.warn "*** Submariner - No subdomain detected"
|
17
|
+
return @app.call(env) unless matches
|
18
|
+
end
|
19
|
+
subdomain = matches[1]
|
20
|
+
|
21
|
+
if Submariner::WildCardSubdomain.subdomains_to_ignore.include?(subdomain)
|
22
|
+
Rails.logger.warn "*** Submariner - skipped domain #{subdomain} based on configuration"
|
23
|
+
return @app.call(env)
|
24
|
+
end
|
25
|
+
Rails.logger.warn "*** Submariner - detected domain #{subdomain}"
|
26
|
+
Submariner::WildCardSubdomain.subdomain_block.call(subdomain)
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/submariner.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "submariner/railtie" if defined? Rails
|
2
|
+
module Submariner
|
3
|
+
class WildCardSubdomain
|
4
|
+
|
5
|
+
cattr_accessor :subdomains_to_ignore
|
6
|
+
@@subdomain_block = nil
|
7
|
+
|
8
|
+
def self.subdomain_block= block
|
9
|
+
@@subdomain_block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.subdomain_block
|
13
|
+
@@subdomain_block
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.config &block
|
17
|
+
block.call(self)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: submariner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Gamble
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sqlite3
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Easy wildcard domains in rails
|
47
|
+
email:
|
48
|
+
- adamgamble@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/rack/wildcard_subdomains.rb
|
54
|
+
- lib/submariner/railtie.rb
|
55
|
+
- lib/submariner/version.rb
|
56
|
+
- lib/submariner.rb
|
57
|
+
- lib/tasks/submariner_tasks.rake
|
58
|
+
- MIT-LICENSE
|
59
|
+
- Rakefile
|
60
|
+
- README.md
|
61
|
+
homepage: http://www.github.com/adamgamble/submariner
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: -2923431994617659417
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
hash: -2923431994617659417
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.24
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Easy wildcard domains in rails
|
91
|
+
test_files: []
|