sinatra-subdomain 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/.travis.yml +12 -0
- data/{README.rdoc → README.md} +50 -27
- data/Rakefile +9 -8
- data/lib/sinatra/subdomain.rb +8 -1
- data/lib/sinatra/subdomain/version.rb +3 -3
- data/sinatra-subdomain.gemspec +5 -6
- data/test/sinatra-subdomain/ip_address_test.rb +21 -0
- data/test/sinatra-subdomain/multiple_subdomain_test.rb +6 -0
- data/test/sinatra-subdomain/multiple_tlds_test.rb +6 -0
- data/test/sinatra-subdomain/single_tld_test.rb +6 -0
- data/test/support/app.rb +21 -0
- data/test/support/subdomain_tests.rb +69 -0
- data/test/test_helper.rb +14 -4
- metadata +69 -59
- data/.rspec +0 -1
- data/Gemfile.lock +0 -53
- data/spec/multiple_tlds_spec.rb +0 -6
- data/spec/single_tld_spec.rb +0 -6
- data/spec/spec_helper.rb +0 -9
- data/spec/support/subdomain_shared.rb +0 -73
- data/test/multiple_tlds_test.rb +0 -46
- data/test/subdomain_test.rb +0 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 08247d5419cc684ee82146875f924297a68f89d6
|
4
|
+
data.tar.gz: 0f38bbcf7aec377e4f3f6c10bd414e0545f1bfb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccad68580ee9adc7b692dfc9ab9234c1d9398225419cc20b211c396ca1a089721df9c8e1fab00950ed54eedcc98df7468ade3053316867f3a93f23e3bd37cc6a
|
7
|
+
data.tar.gz: 5f39b2df84cd7fd9a962ed3ad25de5587d1e63f5ff0ed0ce731d8e293d5f5d12b169152f64df87a586a0431cff6c91fcc594200407fdee6832eb3a2a5898ad39
|
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
pkg
|
1
|
+
pkg
|
2
|
+
*.lock
|
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
sudo: false
|
4
|
+
notifictions:
|
5
|
+
email: false
|
6
|
+
rvm:
|
7
|
+
- 2.3.0
|
8
|
+
- '2.2'
|
9
|
+
- '2.1'
|
10
|
+
env:
|
11
|
+
global:
|
12
|
+
secure: Zq3YrKeSaVI0U5bcYDDnCOxbQDHPpPmTrNGe0M2qtVwN1tibpULIdZVMGOjJ4C4Ulk8OXqpI63aLkWm7fKIT0bQXvGK+w3bksUIHk2jODHfKb/ZDDfAoKhfU1APXnxcGbw06/FDyihWJFYdxrLZBilnvDmcqVz47DvmFBAlPuQ4=
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,53 +1,76 @@
|
|
1
|
-
|
1
|
+
# Sinatra Subdomain
|
2
2
|
|
3
|
-
|
3
|
+
[![Travis-CI](https://travis-ci.org/fnando/sinatra-subdomain.png)](https://travis-ci.org/fnando/sinatra-subdomain)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/fnando/sinatra-subdomain/badges/gpa.svg)](https://codeclimate.com/github/fnando/sinatra-subdomain)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/fnando/sinatra-subdomain/badges/coverage.svg)](https://codeclimate.com/github/fnando/sinatra-subdomain/coverage)
|
6
|
+
[![Gem](https://img.shields.io/gem/v/sinatra-subdomain.svg)](https://rubygems.org/gems/sinatra-subdomain)
|
7
|
+
[![Gem](https://img.shields.io/gem/dt/sinatra-subdomain.svg)](https://rubygems.org/gems/sinatra-subdomain)
|
4
8
|
|
5
|
-
|
9
|
+
## Installation
|
6
10
|
|
7
|
-
|
11
|
+
```
|
12
|
+
gem install sinatra-subdomain
|
13
|
+
```
|
8
14
|
|
9
|
-
|
10
|
-
require "sinatra/subdomain"
|
15
|
+
## Usage
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
```ruby
|
18
|
+
require "sinatra"
|
19
|
+
require "sinatra/subdomain"
|
20
|
+
|
21
|
+
# Specify which subdomain you want
|
22
|
+
subdomain :foo do
|
23
|
+
get '/' do
|
24
|
+
"render page for FOO"
|
17
25
|
end
|
26
|
+
end
|
18
27
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
28
|
+
# If any subdomain is set
|
29
|
+
subdomain do
|
30
|
+
get '/' do
|
31
|
+
"render page for #{subdomain} subdomain"
|
24
32
|
end
|
33
|
+
end
|
34
|
+
```
|
25
35
|
|
26
36
|
If you're not building a classic app, make sure to register Sinatra::Subdomain yourself:
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
38
|
+
```ruby
|
39
|
+
require "sinatra"
|
40
|
+
require "sinatra/subdomain"
|
41
|
+
|
42
|
+
# Specify which subdomain you want
|
43
|
+
subdomain :foo do
|
44
|
+
get '/' do
|
45
|
+
"render page for FOO"
|
32
46
|
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# If any subdomain is set
|
50
|
+
subdomain do
|
51
|
+
get '/' do
|
52
|
+
"render page for #{subdomain} subdomain"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
33
56
|
|
34
57
|
By default, sinatra-subdomain will consider 1 TLD as in <tt>example.com</tt>.
|
35
58
|
You can specify your TLD size for domains like <tt>example.com.br</tt> or <tt>example.co.uk</tt>.
|
36
59
|
|
37
|
-
|
38
|
-
|
60
|
+
```ruby
|
61
|
+
require "sinatra"
|
62
|
+
require "sinatra/subdomain"
|
39
63
|
|
40
|
-
|
64
|
+
set :tld_size, 2
|
65
|
+
```
|
41
66
|
|
42
67
|
This extension was based on http://github.com/akahn/sinatra-subdomain/
|
43
68
|
|
44
|
-
|
69
|
+
# License
|
45
70
|
|
46
71
|
(The MIT License)
|
47
72
|
|
48
|
-
Copyright © 2010
|
49
|
-
|
50
|
-
* Nando Vieira (http://simplesideias.com.br)
|
73
|
+
Copyright © 2010 - Nando Vieira (http://nandovieira.com)
|
51
74
|
|
52
75
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
53
76
|
|
data/Rakefile
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require "bundler"
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
1
|
+
require "bundler/gem_tasks"
|
4
2
|
require "rake/testtask"
|
5
|
-
|
6
|
-
|
7
|
-
t.
|
8
|
-
t.
|
9
|
-
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
7
|
+
t.warning = false
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :test
|
data/lib/sinatra/subdomain.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "sinatra/base"
|
2
2
|
require "uri"
|
3
|
+
require "resolv"
|
3
4
|
|
4
5
|
module Sinatra
|
5
6
|
module Subdomain
|
@@ -10,9 +11,11 @@ module Sinatra
|
|
10
11
|
module Helpers
|
11
12
|
def subdomain
|
12
13
|
uri = URI.parse("http://#{request.env["HTTP_HOST"]}")
|
14
|
+
return if Sinatra::Subdomain.ip_address?(uri.host)
|
13
15
|
parts = uri.host.split(".")
|
14
16
|
parts.pop(settings.tld_size + 1)
|
15
|
-
|
17
|
+
|
18
|
+
parts.empty? ? nil : parts.join(".")
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
@@ -30,6 +33,10 @@ module Sinatra
|
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
36
|
+
def self.ip_address?(host)
|
37
|
+
host =~ Resolv::IPv4::Regex || host =~ Resolv::IPv6::Regex
|
38
|
+
end
|
39
|
+
|
33
40
|
def self.route_added(verb, path, block)
|
34
41
|
return unless subdomain && app
|
35
42
|
|
data/sinatra-subdomain.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "sinatra/subdomain/version"
|
1
|
+
require "./lib/sinatra/subdomain/version"
|
4
2
|
|
5
3
|
Gem::Specification.new do |s|
|
6
4
|
s.name = "sinatra-subdomain"
|
@@ -10,6 +8,7 @@ Gem::Specification.new do |s|
|
|
10
8
|
s.email = ["fnando.vieira@gmail.com"]
|
11
9
|
s.homepage = "http://rubygems.org/gems/sinatra-subdomain"
|
12
10
|
s.summary = "Separate routes for subdomains on Sinatra"
|
11
|
+
s.license = "MIT"
|
13
12
|
s.description = s.summary
|
14
13
|
|
15
14
|
s.files = `git ls-files`.split("\n")
|
@@ -18,9 +17,9 @@ Gem::Specification.new do |s|
|
|
18
17
|
s.require_paths = ["lib"]
|
19
18
|
|
20
19
|
s.add_dependency "sinatra"
|
21
|
-
s.add_development_dependency "
|
20
|
+
s.add_development_dependency "minitest-utils"
|
22
21
|
s.add_development_dependency "rake"
|
23
22
|
s.add_development_dependency "rack-test"
|
24
|
-
s.add_development_dependency "pry"
|
25
|
-
s.add_development_dependency "
|
23
|
+
s.add_development_dependency "pry-meta"
|
24
|
+
s.add_development_dependency "codeclimate-test-reporter"
|
26
25
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class IpAddressTest < Minitest::Test
|
4
|
+
def app
|
5
|
+
App
|
6
|
+
end
|
7
|
+
|
8
|
+
test "renders no subdomain root page" do
|
9
|
+
header "HOST", "127.0.0.1"
|
10
|
+
get "/"
|
11
|
+
|
12
|
+
assert_equal "root", last_response.body
|
13
|
+
end
|
14
|
+
|
15
|
+
test "renders no subdomain about page" do
|
16
|
+
header "HOST", "127.0.0.1"
|
17
|
+
get "/about"
|
18
|
+
|
19
|
+
assert_equal "about", last_response.body
|
20
|
+
end
|
21
|
+
end
|
data/test/support/app.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class App < Sinatra::Base
|
2
|
+
register Sinatra::Subdomain
|
3
|
+
|
4
|
+
subdomain :foo do
|
5
|
+
get("/") { "set: #{subdomain}" }
|
6
|
+
get("/about") { "set: about #{subdomain}" }
|
7
|
+
end
|
8
|
+
|
9
|
+
subdomain "foo.bar" do
|
10
|
+
get("/") { "multiple: #{subdomain}" }
|
11
|
+
get("/about") { "multiple: about #{subdomain}" }
|
12
|
+
end
|
13
|
+
|
14
|
+
subdomain do
|
15
|
+
get("/") { "any: #{subdomain}" }
|
16
|
+
get("/about") { "any: about #{subdomain}" }
|
17
|
+
end
|
18
|
+
|
19
|
+
get("/") { "root" }
|
20
|
+
get("/about") { "about" }
|
21
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module SubdomainTests
|
2
|
+
def app
|
3
|
+
_tld = tld
|
4
|
+
|
5
|
+
Class.new(App) do
|
6
|
+
set :tld_size, _tld.split(".").size - 1
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.class_eval do
|
12
|
+
test "when specific subdomain is required - renders root page" do
|
13
|
+
header "HOST", "foo.example#{tld}"
|
14
|
+
get "/"
|
15
|
+
|
16
|
+
assert_equal "set: foo", last_response.body
|
17
|
+
end
|
18
|
+
|
19
|
+
test "when specific subdomain is required - renders about page" do
|
20
|
+
header "HOST", "foo.example#{tld}"
|
21
|
+
get "/about"
|
22
|
+
|
23
|
+
assert_equal "set: about foo", last_response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
test "when any subdomain is required - renders root page" do
|
27
|
+
header "HOST", "mail.example#{tld}"
|
28
|
+
get "/"
|
29
|
+
|
30
|
+
assert_equal "any: mail",last_response.body
|
31
|
+
end
|
32
|
+
|
33
|
+
test "when any subdomain is required - renders about page" do
|
34
|
+
header "HOST", "mail.example#{tld}"
|
35
|
+
get "/about"
|
36
|
+
|
37
|
+
assert_equal "any: about mail",last_response.body
|
38
|
+
end
|
39
|
+
|
40
|
+
test "when no subdomain is required - renders root page" do
|
41
|
+
header "HOST", "example#{tld}"
|
42
|
+
get "/"
|
43
|
+
|
44
|
+
assert_equal "root",last_response.body
|
45
|
+
end
|
46
|
+
|
47
|
+
test "when no subdomain is required - renders about page" do
|
48
|
+
header "HOST", "example#{tld}"
|
49
|
+
get "/about"
|
50
|
+
|
51
|
+
assert_equal "about",last_response.body
|
52
|
+
end
|
53
|
+
|
54
|
+
test "when multi-subdomain is required - renders root page" do
|
55
|
+
header "HOST", "foo.bar.example#{tld}"
|
56
|
+
get "/"
|
57
|
+
|
58
|
+
assert_equal "multiple: foo.bar",last_response.body
|
59
|
+
end
|
60
|
+
|
61
|
+
test "when multi-subdomain is required - renders about page" do
|
62
|
+
header "HOST", "foo.bar.example#{tld}"
|
63
|
+
get "/about"
|
64
|
+
|
65
|
+
assert_equal "multiple: about foo.bar",last_response.body
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
-
require "test
|
2
|
-
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require "bundler/setup"
|
3
5
|
|
6
|
+
require "minitest/utils"
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "rack/test"
|
4
9
|
require "sinatra/subdomain"
|
10
|
+
require "yaml"
|
11
|
+
|
12
|
+
Dir["./test/support/**/*.rb"].each {|file| require file }
|
5
13
|
|
6
|
-
|
7
|
-
|
14
|
+
module Minitest
|
15
|
+
class Test
|
16
|
+
include Rack::Test::Methods
|
17
|
+
end
|
8
18
|
end
|
metadata
CHANGED
@@ -1,82 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-subdomain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nando Vieira
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: sinatra
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: minitest-utils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: rack-test
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
|
-
name: pry
|
60
|
-
requirement:
|
61
|
-
none: false
|
70
|
+
name: pry-meta
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
|
-
- -
|
73
|
+
- - ">="
|
64
74
|
- !ruby/object:Gem::Version
|
65
75
|
version: '0'
|
66
76
|
type: :development
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement:
|
72
|
-
none: false
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- -
|
87
|
+
- - ">="
|
75
88
|
- !ruby/object:Gem::Version
|
76
89
|
version: '0'
|
77
90
|
type: :development
|
78
91
|
prerelease: false
|
79
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
80
97
|
description: Separate routes for subdomains on Sinatra
|
81
98
|
email:
|
82
99
|
- fnando.vieira@gmail.com
|
@@ -84,57 +101,50 @@ executables: []
|
|
84
101
|
extensions: []
|
85
102
|
extra_rdoc_files: []
|
86
103
|
files:
|
87
|
-
- .gitignore
|
88
|
-
- .
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
89
106
|
- Gemfile
|
90
|
-
-
|
91
|
-
- README.rdoc
|
107
|
+
- README.md
|
92
108
|
- Rakefile
|
93
109
|
- lib/sinatra/subdomain.rb
|
94
110
|
- lib/sinatra/subdomain/version.rb
|
95
111
|
- sinatra-subdomain.gemspec
|
96
|
-
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
- test/
|
101
|
-
- test/
|
112
|
+
- test/sinatra-subdomain/ip_address_test.rb
|
113
|
+
- test/sinatra-subdomain/multiple_subdomain_test.rb
|
114
|
+
- test/sinatra-subdomain/multiple_tlds_test.rb
|
115
|
+
- test/sinatra-subdomain/single_tld_test.rb
|
116
|
+
- test/support/app.rb
|
117
|
+
- test/support/subdomain_tests.rb
|
102
118
|
- test/test_helper.rb
|
103
119
|
homepage: http://rubygems.org/gems/sinatra-subdomain
|
104
|
-
licenses:
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
105
123
|
post_install_message:
|
106
124
|
rdoc_options: []
|
107
125
|
require_paths:
|
108
126
|
- lib
|
109
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
128
|
requirements:
|
112
|
-
- -
|
129
|
+
- - ">="
|
113
130
|
- !ruby/object:Gem::Version
|
114
131
|
version: '0'
|
115
|
-
segments:
|
116
|
-
- 0
|
117
|
-
hash: 632946571034999382
|
118
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
133
|
requirements:
|
121
|
-
- -
|
134
|
+
- - ">="
|
122
135
|
- !ruby/object:Gem::Version
|
123
136
|
version: '0'
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
hash: 632946571034999382
|
127
137
|
requirements: []
|
128
138
|
rubyforge_project:
|
129
|
-
rubygems_version:
|
139
|
+
rubygems_version: 2.5.1
|
130
140
|
signing_key:
|
131
|
-
specification_version:
|
141
|
+
specification_version: 4
|
132
142
|
summary: Separate routes for subdomains on Sinatra
|
133
143
|
test_files:
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
- test/
|
139
|
-
- test/
|
144
|
+
- test/sinatra-subdomain/ip_address_test.rb
|
145
|
+
- test/sinatra-subdomain/multiple_subdomain_test.rb
|
146
|
+
- test/sinatra-subdomain/multiple_tlds_test.rb
|
147
|
+
- test/sinatra-subdomain/single_tld_test.rb
|
148
|
+
- test/support/app.rb
|
149
|
+
- test/support/subdomain_tests.rb
|
140
150
|
- test/test_helper.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color --format documentation
|
data/Gemfile.lock
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
sinatra-subdomain (0.1.2)
|
5
|
-
sinatra
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
awesome_print (1.0.2)
|
11
|
-
coderay (0.9.8)
|
12
|
-
diff-lcs (1.1.3)
|
13
|
-
method_source (0.6.7)
|
14
|
-
ruby_parser (>= 2.3.1)
|
15
|
-
pry (0.9.7.4)
|
16
|
-
coderay (~> 0.9.8)
|
17
|
-
method_source (~> 0.6.7)
|
18
|
-
ruby_parser (>= 2.3.1)
|
19
|
-
slop (~> 2.1.0)
|
20
|
-
rack (1.4.0)
|
21
|
-
rack-protection (1.2.0)
|
22
|
-
rack
|
23
|
-
rack-test (0.6.1)
|
24
|
-
rack (>= 1.0)
|
25
|
-
rake (0.9.2.2)
|
26
|
-
rspec (2.8.0)
|
27
|
-
rspec-core (~> 2.8.0)
|
28
|
-
rspec-expectations (~> 2.8.0)
|
29
|
-
rspec-mocks (~> 2.8.0)
|
30
|
-
rspec-core (2.8.0)
|
31
|
-
rspec-expectations (2.8.0)
|
32
|
-
diff-lcs (~> 1.1.2)
|
33
|
-
rspec-mocks (2.8.0)
|
34
|
-
ruby_parser (2.3.1)
|
35
|
-
sexp_processor (~> 3.0)
|
36
|
-
sexp_processor (3.0.10)
|
37
|
-
sinatra (1.3.2)
|
38
|
-
rack (~> 1.3, >= 1.3.6)
|
39
|
-
rack-protection (~> 1.2)
|
40
|
-
tilt (~> 1.3, >= 1.3.3)
|
41
|
-
slop (2.1.0)
|
42
|
-
tilt (1.3.3)
|
43
|
-
|
44
|
-
PLATFORMS
|
45
|
-
ruby
|
46
|
-
|
47
|
-
DEPENDENCIES
|
48
|
-
awesome_print
|
49
|
-
pry
|
50
|
-
rack-test
|
51
|
-
rake
|
52
|
-
rspec
|
53
|
-
sinatra-subdomain!
|
data/spec/multiple_tlds_spec.rb
DELETED
data/spec/single_tld_spec.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
shared_examples_for "subdomain" do
|
2
|
-
def app
|
3
|
-
@app ||= begin
|
4
|
-
_tld = tld
|
5
|
-
|
6
|
-
@app = Class.new(Sinatra::Base) do
|
7
|
-
register Sinatra::Subdomain
|
8
|
-
set :tld_size, _tld.split(".").size - 1
|
9
|
-
|
10
|
-
subdomain :foo do
|
11
|
-
get("/") { "set: #{subdomain}" }
|
12
|
-
get("/about") { "set: about #{subdomain}" }
|
13
|
-
end
|
14
|
-
|
15
|
-
subdomain do
|
16
|
-
get("/") { "any: #{subdomain}" }
|
17
|
-
get("/about") { "any: about #{subdomain}" }
|
18
|
-
end
|
19
|
-
|
20
|
-
get("/") { "root" }
|
21
|
-
get("/about") { "about" }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when specific subdomain is required" do
|
27
|
-
it "renders root page" do
|
28
|
-
header "HOST", "foo.example#{tld}"
|
29
|
-
get "/"
|
30
|
-
|
31
|
-
last_response.body.should eql("set: foo")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "renders about page" do
|
35
|
-
header "HOST", "foo.example#{tld}"
|
36
|
-
get "/about"
|
37
|
-
|
38
|
-
last_response.body.should eql("set: about foo")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when any subdomain is required" do
|
43
|
-
it "renders root page" do
|
44
|
-
header "HOST", "mail.example#{tld}"
|
45
|
-
get "/"
|
46
|
-
|
47
|
-
last_response.body.should eql("any: mail")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "renders about page" do
|
51
|
-
header "HOST", "mail.example#{tld}"
|
52
|
-
get "/about"
|
53
|
-
|
54
|
-
last_response.body.should eql("any: about mail")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when no subdomain is required" do
|
59
|
-
it "renders root page" do
|
60
|
-
header "HOST", "example#{tld}"
|
61
|
-
get "/"
|
62
|
-
|
63
|
-
last_response.body.should eql("root")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "renders about page" do
|
67
|
-
header "HOST", "example#{tld}"
|
68
|
-
get "/about"
|
69
|
-
|
70
|
-
last_response.body.should eql("about")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/test/multiple_tlds_test.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class MultipleTldsTest < Test::Unit::TestCase
|
4
|
-
App = Class.new(Sinatra::Base) do
|
5
|
-
register Sinatra::Subdomain
|
6
|
-
set :tld_size, 2
|
7
|
-
|
8
|
-
subdomain :foo do
|
9
|
-
get("/") { "set: #{subdomain}" }
|
10
|
-
end
|
11
|
-
|
12
|
-
subdomain do
|
13
|
-
get("/") { "any: #{subdomain}" }
|
14
|
-
end
|
15
|
-
|
16
|
-
get("/") { "root" }
|
17
|
-
end
|
18
|
-
|
19
|
-
def app
|
20
|
-
App
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_specified_subdomain
|
24
|
-
header "HOST", "foo.example.com.br"
|
25
|
-
get "/"
|
26
|
-
|
27
|
-
assert_equal "set: foo", last_response.body
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_any_subdomain
|
31
|
-
header "HOST", "status.example.com.br"
|
32
|
-
get "/"
|
33
|
-
assert_equal "any: status", last_response.body
|
34
|
-
|
35
|
-
header "HOST", "mail.example.com.br"
|
36
|
-
get "/"
|
37
|
-
assert_equal "any: mail", last_response.body
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_root
|
41
|
-
header "HOST", "example.com.br"
|
42
|
-
get "/"
|
43
|
-
|
44
|
-
assert_equal "root", last_response.body
|
45
|
-
end
|
46
|
-
end
|
data/test/subdomain_test.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class SubdomainTest < Test::Unit::TestCase
|
4
|
-
App = Class.new(Sinatra::Base) do
|
5
|
-
register Sinatra::Subdomain
|
6
|
-
|
7
|
-
subdomain :foo do
|
8
|
-
get("/") { "set: #{subdomain}" }
|
9
|
-
end
|
10
|
-
|
11
|
-
subdomain do
|
12
|
-
get("/") { "any: #{subdomain}" }
|
13
|
-
end
|
14
|
-
|
15
|
-
get("/") { "root" }
|
16
|
-
end
|
17
|
-
|
18
|
-
def app
|
19
|
-
App
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_specified_subdomain
|
23
|
-
header "HOST", "foo.example.org"
|
24
|
-
get "/"
|
25
|
-
|
26
|
-
assert_equal "set: foo", last_response.body
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_any_subdomain
|
30
|
-
header "HOST", "status.example.org"
|
31
|
-
get "/"
|
32
|
-
assert_equal "any: status", last_response.body
|
33
|
-
|
34
|
-
header "HOST", "mail.example.org"
|
35
|
-
get "/"
|
36
|
-
assert_equal "any: mail", last_response.body
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_root
|
40
|
-
header "HOST", "example.org"
|
41
|
-
get "/"
|
42
|
-
|
43
|
-
assert_equal "root", last_response.body
|
44
|
-
end
|
45
|
-
end
|