sinatra-subroutes 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ # gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "sinatra", ">= 0"
13
+ # gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rack (1.2.1)
10
+ rake (0.8.7)
11
+ sinatra (1.1.0)
12
+ rack (~> 1.1)
13
+ tilt (~> 1.1)
14
+ tilt (1.1)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ jeweler (~> 1.5.2)
22
+ sinatra
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Daniel Westendorf
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.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ sinatra-subroutes
2
+ =================
3
+
4
+ Create Sinatra routes that respond to the subdomain defined, similar to the built in user_agent option. Compiled into a gem from these sources:
5
+ http://tannerburson.com/2009/01/extracting-subdomains-in-sinatra.html
6
+ http://toms-toolbox.com/2010/04/sinatra-native-subdomain-routing/
7
+
8
+ Install
9
+ -------
10
+ <pre>
11
+ gem install sinatra-subroutes
12
+ </pre>
13
+
14
+ Usage
15
+ -----
16
+ <pre>
17
+ require 'sinatra'
18
+ require 'sinatra-subroutes'
19
+
20
+ set :tld_size, 2 # Use this for domains such as example.co.uk, default is 1
21
+
22
+ get '/', :subdomain => /subdomain/ do
23
+ 'You're at the root of the "subdomain" subdomain'
24
+ end
25
+ </pre>
26
+
27
+
28
+ == Contributing to sinatra-subroutes
29
+
30
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
31
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
32
+ * Fork the project
33
+ * Start a feature/bugfix branch
34
+ * Commit and push until you are happy with your contribution
35
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
36
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
37
+
38
+ == Copyright
39
+
40
+ Copyright (c) 2010 Daniel Westendorf. See LICENSE.txt for
41
+ further details.
42
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "sinatra-subroutes"
16
+ gem.homepage = "http://github.com/danielwestendorf/sinatra-subroutes"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Allows restricting routes to a subdomain}
19
+ gem.description = %Q{Restrict routes in Sinatra based of the Subdomain in the URI}
20
+ gem.email = "daniel@prowestech.com"
21
+ gem.authors = ["Daniel Westendorf"]
22
+ gem.add_runtime_dependency 'sinatra', ">=0"
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
+
26
+ #require 'rake/testtask'
27
+ #Rake::TestTask.new(:test) do |test|
28
+ # test.libs << 'lib' << 'test'
29
+ # test.pattern = 'test/**/test_*.rb'
30
+ # test.verbose = true
31
+ #end
32
+
33
+ #require 'rcov/rcovtask'
34
+ #Rcov::RcovTask.new do |test|
35
+ # test.libs << 'test'
36
+ # test.pattern = 'test/**/test_*.rb'
37
+ # test.verbose = true
38
+ #end
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "sinatra-subroutes #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,41 @@
1
+ # This method is heavily adapted from the Rails method of determining the subdomain.
2
+ require 'rubygems'
3
+ require 'sinatra'
4
+
5
+ require 'rack/request'
6
+
7
+ # Extracted from http://tannerburson.com/2009/01/extracting-subdomains-in-sinatra.html
8
+ # We re-open the request class to add the subdomains method
9
+ module Rack
10
+ class Request
11
+ def subdomains(tld_len=1) # we set tld_len to 1, use 2 for co.uk or similar
12
+ # cache the result so we only compute it once.
13
+ @env['rack.env.subdomains'] ||= lambda {
14
+ # check if the current host is an IP address, if so return an empty array
15
+ return [] if (host.nil? ||
16
+ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
17
+ host.split('.')[0...(1 - tld_len - 2)] # pull everything except the TLD
18
+ }.call
19
+ end
20
+ end
21
+ end
22
+
23
+ module Sinatra
24
+ class Base
25
+ class << self
26
+
27
+ # Adapted from here: http://toms-toolbox.com/2010/04/sinatra-native-subdomain-routing/
28
+ def subdomain(pattern)
29
+ condition {
30
+ if request.subdomains[0] =~ pattern
31
+ @params[:subdomain] = $~[1..-1]
32
+ true
33
+ else
34
+ false
35
+ end
36
+ }
37
+ end
38
+
39
+ end
40
+ end
41
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'sinatra-subroutes'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSinatraSubroutes < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-subroutes
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Daniel Westendorf
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-21 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 5
45
+ - 2
46
+ version: 1.5.2
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: sinatra
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: sinatra
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ description: Restrict routes in Sinatra based of the Subdomain in the URI
77
+ email: daniel@prowestech.com
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - lib/sinatra-subroutes.rb
94
+ - test/helper.rb
95
+ - test/test_sinatra-subroutes.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/danielwestendorf/sinatra-subroutes
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: -1460868835323445709
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.3.7
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Allows restricting routes to a subdomain
129
+ test_files:
130
+ - test/helper.rb
131
+ - test/test_sinatra-subroutes.rb