sinatra-subdomain 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e503ce75701c38cf44dacb5e113445a0c318961e
4
- data.tar.gz: d693c87a48d2061ef0066da58795764e93244bb3
2
+ SHA256:
3
+ metadata.gz: 2f8c53e74401f55a751115abc8e9100a54a5610e8ce6560e796885841e86b8e0
4
+ data.tar.gz: a4c173180de33d07cd060c566c4d4cff7f83174b31e0e61f3b71386c5a12cab5
5
5
  SHA512:
6
- metadata.gz: ae45d43735b5e6f8e66122ba052cdb832035030b364e69cb7df5109571176bfc60f90e6ee8acede0fd30d218731a9f4c2efae0d481289922e3112952e82ef3f5
7
- data.tar.gz: fc0cb786be4891dc12cdb80e528af1934311594ce0f708f6307e5ad625e62391f4ffcc524f8b4ada12a4009b3fbe8af05ea0a486d1d92ee84ad7fffa707ff84d
6
+ metadata.gz: 49bfccce1571b7ea19670bac0aee42959efc3ec6af384a47a949c19d46e2f08f2aaca3ae82dff3c0092d2af7a92d9e60577ce41d3b5311502da509ec8ed9d9ad
7
+ data.tar.gz: a51325cf941367814569bdf4700f665b90ec54d42e521e49384763049a17db48026298ecaed11986355065f1db54fce195d11964a1c90513670ea8b058f009db
@@ -0,0 +1,3 @@
1
+ ---
2
+ github: [fnando]
3
+ custom: ["https://www.paypal.me/nandovieira/🍕"]
@@ -0,0 +1,23 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+
9
+ Naming/FileName:
10
+ Exclude:
11
+ - lib/sinatra-subdomain.rb
12
+
13
+ Style/OptionalBooleanParameter:
14
+ Enabled: false
15
+
16
+ Metrics/MethodLength:
17
+ Enabled: false
18
+
19
+ Metrics/BlockLength:
20
+ Enabled: false
21
+
22
+ Metrics/AbcSize:
23
+ Enabled: false
@@ -6,13 +6,13 @@ notifications:
6
6
  email: false
7
7
 
8
8
  rvm:
9
- - 2.2.6
10
- - 2.3.3
11
- - 2.4.0
9
+ - 2.7.1
10
+ - 2.6.5
12
11
 
13
12
  gemfile:
14
- - gemfiles/sinatra_2.gemfile
15
- - gemfiles/sinatra_1.gemfile
13
+ - gemfiles/sinatra_2_1.gemfile
14
+ - gemfiles/sinatra_2_0.gemfile
15
+ - gemfiles/sinatra_1_4.gemfile
16
16
 
17
17
  env:
18
18
  global:
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Sinatra Subdomain
2
2
 
3
- [![Travis-CI](https://travis-ci.org/fnando/sinatra-subdomain.png)](https://travis-ci.org/fnando/sinatra-subdomain)
3
+ [![Travis-CI](https://travis-ci.org/fnando/sinatra-subdomain.svg)](https://travis-ci.org/fnando/sinatra-subdomain)
4
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
5
  [![Gem](https://img.shields.io/gem/v/sinatra-subdomain.svg)](https://rubygems.org/gems/sinatra-subdomain)
7
6
  [![Gem](https://img.shields.io/gem/dt/sinatra-subdomain.svg)](https://rubygems.org/gems/sinatra-subdomain)
8
7
 
@@ -33,7 +32,8 @@ subdomain do
33
32
  end
34
33
  ```
35
34
 
36
- If you're not building a classic app, make sure to register Sinatra::Subdomain yourself:
35
+ If you're not building a classic app, make sure to register Sinatra::Subdomain
36
+ yourself:
37
37
 
38
38
  ```ruby
39
39
  require "sinatra"
@@ -58,7 +58,7 @@ class MyApp < Sinatra::Base
58
58
  end
59
59
  ```
60
60
 
61
- You can also pass an array or regular expressions to match subdomains:
61
+ You can also pass an array, regular expressions to match subdomains, or a proc:
62
62
 
63
63
  ```ruby
64
64
  class MyApp < Sinatra::Base
@@ -76,11 +76,22 @@ class MyApp < Sinatra::Base
76
76
  "render page for #{subdomain} subdomain"
77
77
  end
78
78
  end
79
+
80
+ app_matcher = lambda do |subdomain|
81
+ App.where(subdomain: actual_subdomain).exist?
82
+ end
83
+
84
+ subdomain(app_matcher) do
85
+ get "/" do
86
+ "render page for #{subdomain} app"
87
+ end
88
+ end
79
89
  end
80
90
  ```
81
91
 
82
92
  By default, sinatra-subdomain will consider 1 TLD as in <tt>example.com</tt>.
83
- You can specify your TLD size for domains like <tt>example.com.br</tt> or <tt>example.co.uk</tt>.
93
+ You can specify your TLD size for domains like <tt>example.com.br</tt> or
94
+ <tt>example.co.uk</tt>.
84
95
 
85
96
  ```ruby
86
97
  require "sinatra"
@@ -95,8 +106,19 @@ set :tld_size, 2
95
106
 
96
107
  Copyright © 2010 - Nando Vieira (http://nandovieira.com)
97
108
 
98
- 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:
99
-
100
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
101
-
102
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
109
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
110
+ this software and associated documentation files (the ‘Software’), to deal in
111
+ the Software without restriction, including without limitation the rights to
112
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
113
+ the Software, and to permit persons to whom the Software is furnished to do so,
114
+ subject to the following conditions:
115
+
116
+ The above copyright notice and this permission notice shall be included in all
117
+ copies or substantial portions of the Software.
118
+
119
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
120
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
121
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
122
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
123
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
124
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
8
  t.libs << "test"
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
7
10
  t.warning = false
8
11
  end
9
12
 
10
- task default: :test
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
@@ -1,4 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec path: ".."
3
3
 
4
- gem "sinatra", "~> 2.0.0.beta2"
4
+ gem "sinatra", "~> 2.0.0"
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec path: ".."
3
+
4
+ gem "sinatra", "~> 2.1.0"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "sinatra/base"
2
4
  require "uri"
3
5
  require "resolv"
@@ -8,10 +10,15 @@ module Sinatra
8
10
  attr_accessor :app, :subdomain
9
11
  end
10
12
 
13
+ SINATRA_V2 = Gem::Requirement.create([">=2.0"]).satisfied_by?(
14
+ Gem::Version.create(Sinatra::VERSION)
15
+ )
16
+
11
17
  module Helpers
12
18
  def subdomain
13
- uri = URI.parse("http://#{request.env["HTTP_HOST"]}")
19
+ uri = URI.parse("http://#{request.env['HTTP_HOST']}")
14
20
  return if Sinatra::Subdomain.ip_address?(uri.host)
21
+
15
22
  parts = uri.host.split(".")
16
23
  parts.pop(settings.tld_size + 1)
17
24
 
@@ -19,6 +26,17 @@ module Sinatra
19
26
  end
20
27
  end
21
28
 
29
+ # This is how this works:
30
+ #
31
+ # 1. Whenever you call `subdomain(&block)`, this is the method that's going
32
+ # to be executed.
33
+ # 2. For each `subdomain` block, we set the app and subdomain condition as
34
+ # `Sinatra::Subdomain.app` and `Sinatra::Subdomain.subdomain`.
35
+ # 3. Then, we yield the block, which will add the routes as needed.
36
+ # 4. After each route is added, Sinatra triggers a hook called
37
+ # `:route_added`, handled by the `routed_added` method below.
38
+ # 5. The `routed_added` method will hijack the routes, adding the subdomain
39
+ # condition.
22
40
  def subdomain(expected_subdomain = true)
23
41
  ::Sinatra::Subdomain.tap do |mod|
24
42
  mod.app = self
@@ -45,7 +63,7 @@ module Sinatra
45
63
  when Symbol
46
64
  actual.to_s == expected_subdomain.to_s
47
65
  else
48
- expected_subdomain === actual
66
+ expected_subdomain === actual # rubocop:disable Style/CaseEquality
49
67
  end
50
68
  end
51
69
  end
@@ -58,7 +76,7 @@ module Sinatra
58
76
  expected = [subdomain].flatten.compact
59
77
 
60
78
  condition = app.instance_eval do
61
- generate_method :subdomain do
79
+ generate_method :subdomain_matcher do
62
80
  ::Sinatra::Subdomain.match_subdomain?(expected, subdomain)
63
81
  end
64
82
  end
@@ -66,7 +84,7 @@ module Sinatra
66
84
  add_condition(last_route, condition)
67
85
  end
68
86
 
69
- if Gem::Requirement.create(["~>2.0"]).satisfied_by?(Gem::Version.create(Sinatra::VERSION))
87
+ if SINATRA_V2
70
88
  def self.add_condition(last_route, condition)
71
89
  last_route[1] << condition
72
90
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sinatra
2
4
  module Subdomain
3
5
  module Version
4
6
  MAJOR = 0
5
- MINOR = 3
7
+ MINOR = 4
6
8
  PATCH = 0
7
9
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "./lib/sinatra/subdomain/version"
2
4
 
3
5
  Gem::Specification.new do |s|
@@ -10,16 +12,21 @@ Gem::Specification.new do |s|
10
12
  s.summary = "Separate routes for subdomains on Sinatra"
11
13
  s.license = "MIT"
12
14
  s.description = s.summary
15
+ s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
13
16
 
14
17
  s.files = `git ls-files`.split("\n")
15
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f) }
19
+ s.executables = `git ls-files -- bin/*`
20
+ .split("\n")
21
+ .map {|f| File.basename(f) }
17
22
  s.require_paths = ["lib"]
18
23
 
19
24
  s.add_dependency "sinatra"
20
25
  s.add_development_dependency "minitest-utils"
21
- s.add_development_dependency "rake"
22
- s.add_development_dependency "rack-test"
23
26
  s.add_development_dependency "pry-meta"
24
- s.add_development_dependency "codeclimate-test-reporter"
27
+ s.add_development_dependency "rack-test"
28
+ s.add_development_dependency "rake"
29
+ s.add_development_dependency "rubocop"
30
+ s.add_development_dependency "rubocop-fnando"
31
+ s.add_development_dependency "simplecov"
25
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class IpAddressTest < Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class MultipleSubdomainTest < Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class MultipleTldsTest < Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class SingleTldTest < Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class SubdomainsTest < Minitest::Test
@@ -32,4 +34,11 @@ class SubdomainsTest < Minitest::Test
32
34
 
33
35
  assert_equal "regex: d", last_response.body
34
36
  end
37
+
38
+ test "renders matched subdomain (e)" do
39
+ header "HOST", "e.example.com"
40
+ get "/"
41
+
42
+ assert_equal "proc: e", last_response.body
43
+ end
35
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class App < Sinatra::Base
2
4
  register Sinatra::Subdomain
3
5
 
@@ -15,10 +17,14 @@ class App < Sinatra::Base
15
17
  get("/") { "array: #{subdomain}" }
16
18
  end
17
19
 
18
- subdomain /\A(c|d)\z/ do
20
+ subdomain(/\A(c|d)\z/) do
19
21
  get("/") { "regex: #{subdomain}" }
20
22
  end
21
23
 
24
+ subdomain(->(actual) { actual == "e" }) do
25
+ get("/") { "proc: #{subdomain}" }
26
+ end
27
+
22
28
  subdomain do
23
29
  get("/") { "any: #{subdomain}" }
24
30
  get("/about") { "any: about #{subdomain}" }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SubdomainTests
2
4
  def app
3
5
  current_tld = tld
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "simplecov"
2
4
  SimpleCov.start
3
5
 
@@ -9,7 +11,7 @@ require "rack/test"
9
11
  require "sinatra/subdomain"
10
12
  require "yaml"
11
13
 
12
- Dir["./test/support/**/*.rb"].each {|file| require file }
14
+ Dir["./test/support/**/*.rb"].sort.each {|file| require file }
13
15
 
14
16
  module Minitest
15
17
  class Test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-subdomain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: pry-meta
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry-meta
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,35 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: codeclimate-test-reporter
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-fnando
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -101,13 +129,16 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
132
+ - ".github/FUNDING.yml"
104
133
  - ".gitignore"
134
+ - ".rubocop.yml"
105
135
  - ".travis.yml"
106
136
  - Gemfile
107
137
  - README.md
108
138
  - Rakefile
109
- - gemfiles/sinatra_1.gemfile
110
- - gemfiles/sinatra_2.gemfile
139
+ - gemfiles/sinatra_1_4.gemfile
140
+ - gemfiles/sinatra_2_0.gemfile
141
+ - gemfiles/sinatra_2_1.gemfile
111
142
  - lib/sinatra/subdomain.rb
112
143
  - lib/sinatra/subdomain/version.rb
113
144
  - sinatra-subdomain.gemspec
@@ -123,7 +154,7 @@ homepage: http://rubygems.org/gems/sinatra-subdomain
123
154
  licenses:
124
155
  - MIT
125
156
  metadata: {}
126
- post_install_message:
157
+ post_install_message:
127
158
  rdoc_options: []
128
159
  require_paths:
129
160
  - lib
@@ -131,16 +162,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
162
  requirements:
132
163
  - - ">="
133
164
  - !ruby/object:Gem::Version
134
- version: '0'
165
+ version: 2.5.0
135
166
  required_rubygems_version: !ruby/object:Gem::Requirement
136
167
  requirements:
137
168
  - - ">="
138
169
  - !ruby/object:Gem::Version
139
170
  version: '0'
140
171
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.6.11
143
- signing_key:
172
+ rubygems_version: 3.1.2
173
+ signing_key:
144
174
  specification_version: 4
145
175
  summary: Separate routes for subdomains on Sinatra
146
176
  test_files: