circuit 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +34 -0
- data/LICENSE +20 -0
- data/README.md +161 -0
- data/Rakefile +27 -0
- data/config.ru +7 -0
- data/description.md +5 -0
- data/docs/COMPATIBILITY.md +14 -0
- data/docs/ROADMAP.md +29 -0
- data/lib/circuit.rb +125 -0
- data/lib/circuit/behavior.rb +99 -0
- data/lib/circuit/compatibility.rb +73 -0
- data/lib/circuit/middleware.rb +6 -0
- data/lib/circuit/middleware/rewriter.rb +43 -0
- data/lib/circuit/rack.rb +14 -0
- data/lib/circuit/rack/behavioral.rb +45 -0
- data/lib/circuit/rack/builder.rb +50 -0
- data/lib/circuit/rack/multi_site.rb +22 -0
- data/lib/circuit/rack/request.rb +81 -0
- data/lib/circuit/railtie.rb +24 -0
- data/lib/circuit/storage.rb +74 -0
- data/lib/circuit/storage/memory_model.rb +70 -0
- data/lib/circuit/storage/nodes.rb +56 -0
- data/lib/circuit/storage/nodes/memory_store.rb +63 -0
- data/lib/circuit/storage/nodes/model.rb +67 -0
- data/lib/circuit/storage/nodes/mongoid_store.rb +56 -0
- data/lib/circuit/storage/sites.rb +38 -0
- data/lib/circuit/storage/sites/memory_store.rb +53 -0
- data/lib/circuit/storage/sites/model.rb +29 -0
- data/lib/circuit/storage/sites/mongoid_store.rb +43 -0
- data/lib/circuit/validators.rb +74 -0
- data/lib/circuit/version.rb +3 -0
- data/spec/internal/app/behaviors/change_path.rb +7 -0
- data/spec/internal/app/controllers/application_controller.rb +5 -0
- data/spec/internal/app/helpers/application_helper.rb +2 -0
- data/spec/internal/config/initializers/circuit.rb +7 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +1 -0
- data/spec/lib/circuit/behavior_spec.rb +113 -0
- data/spec/lib/circuit/middleware/rewriter_spec.rb +79 -0
- data/spec/lib/circuit/rack/behavioral_spec.rb +60 -0
- data/spec/lib/circuit/rack/builder_spec.rb +125 -0
- data/spec/lib/circuit/rack/multi_site_spec.rb +34 -0
- data/spec/lib/circuit/rack/request_spec.rb +80 -0
- data/spec/lib/circuit/railtie_spec.rb +34 -0
- data/spec/lib/circuit/storage/nodes_spec.rb +62 -0
- data/spec/lib/circuit/storage/sites_spec.rb +60 -0
- data/spec/lib/circuit/storage_spec.rb +20 -0
- data/spec/lib/circuit/validators_spec.rb +69 -0
- data/spec/lib/circuit_spec.rb +139 -0
- data/spec/spec_helper.rb +79 -0
- data/spec/support/blueprints.rb +24 -0
- data/spec/support/matchers/be_current_time_matcher.rb +14 -0
- data/spec/support/matchers/extended_have_key.rb +31 -0
- data/spec/support/matchers/have_accessor_matcher.rb +13 -0
- data/spec/support/matchers/have_attribute_matcher.rb +22 -0
- data/spec/support/matchers/have_block_matcher.rb +14 -0
- data/spec/support/matchers/have_errors_on_matcher.rb +30 -0
- data/spec/support/matchers/have_module_matcher.rb +13 -0
- data/spec/support/matchers/have_reader_matcher.rb +18 -0
- data/spec/support/matchers/have_writer_matcher.rb +18 -0
- data/spec/support/matchers/set_instance_variable.rb +32 -0
- data/spec/support/spec_helpers/base_behaviors.rb +20 -0
- data/spec/support/spec_helpers/base_models.rb +64 -0
- data/spec/support/spec_helpers/logger_helpers.rb +58 -0
- data/spec/support/spec_helpers/multi_site_helper.rb +48 -0
- data/spec/support/spec_helpers/rack_helpers.rb +8 -0
- data/spec/support/spec_helpers/shared_examples/node_store.rb +87 -0
- data/spec/support/spec_helpers/shared_examples/site_store.rb +76 -0
- data/spec/support/spec_helpers/simple_machinable.rb +29 -0
- data/spec/support/spec_helpers/stores_cleaner.rb +46 -0
- data/vendor/active_support-3.2/core_ext/string/inflections.rb +53 -0
- data/vendor/active_support-3.2/inflector/methods.rb +65 -0
- data/vendor/rack-1.4/builder.rb +167 -0
- data/vendor/rack-1.4/urlmap.rb +96 -0
- metadata +238 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
## Copied from Rack 1.4.1 on 19 June 2012.
|
2
|
+
## see http://github.com/rack/rack/blob/1.4.1/lib/rack/urlmap.rb
|
3
|
+
|
4
|
+
# Copyright (c) 2007, 2008, 2009, 2010 Christian Neukirchen <purl.org/net/chneukirchen>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to
|
8
|
+
# deal in the Software without restriction, including without limitation the
|
9
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
+
# sell copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19
|
+
# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
20
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
module Rack
|
24
|
+
# Rack::URLMap takes a hash mapping urls or paths to apps, and
|
25
|
+
# dispatches accordingly. Support for HTTP/1.1 host names exists if
|
26
|
+
# the URLs start with <tt>http://</tt> or <tt>https://</tt>.
|
27
|
+
#
|
28
|
+
# URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part
|
29
|
+
# relevant for dispatch is in the SCRIPT_NAME, and the rest in the
|
30
|
+
# PATH_INFO. This should be taken care of when you need to
|
31
|
+
# reconstruct the URL in order to create links.
|
32
|
+
#
|
33
|
+
# URLMap dispatches in such a way that the longest paths are tried
|
34
|
+
# first, since they are most specific.
|
35
|
+
|
36
|
+
class URLMap
|
37
|
+
NEGATIVE_INFINITY = -1.0 / 0.0
|
38
|
+
|
39
|
+
def initialize(map = {})
|
40
|
+
remap(map)
|
41
|
+
end
|
42
|
+
|
43
|
+
def remap(map)
|
44
|
+
@mapping = map.map { |location, app|
|
45
|
+
if location =~ %r{\Ahttps?://(.*?)(/.*)}
|
46
|
+
host, location = $1, $2
|
47
|
+
else
|
48
|
+
host = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
unless location[0] == ?/
|
52
|
+
raise ArgumentError, "paths need to start with /"
|
53
|
+
end
|
54
|
+
|
55
|
+
location = location.chomp('/')
|
56
|
+
match = Regexp.new("^#{Regexp.quote(location).gsub('/', '/+')}(.*)", nil, 'n')
|
57
|
+
|
58
|
+
[host, location, match, app]
|
59
|
+
}.sort_by do |(host, location, _, _)|
|
60
|
+
[host ? -host.size : NEGATIVE_INFINITY, -location.size]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def call(env)
|
65
|
+
path = env["PATH_INFO"]
|
66
|
+
script_name = env['SCRIPT_NAME']
|
67
|
+
hHost = env['HTTP_HOST']
|
68
|
+
sName = env['SERVER_NAME']
|
69
|
+
sPort = env['SERVER_PORT']
|
70
|
+
|
71
|
+
@mapping.each do |host, location, match, app|
|
72
|
+
unless hHost == host \
|
73
|
+
|| sName == host \
|
74
|
+
|| (!host && (hHost == sName || hHost == sName+':'+sPort))
|
75
|
+
next
|
76
|
+
end
|
77
|
+
|
78
|
+
next unless m = match.match(path.to_s)
|
79
|
+
|
80
|
+
rest = m[1]
|
81
|
+
next unless !rest || rest.empty? || rest[0] == ?/
|
82
|
+
|
83
|
+
env['SCRIPT_NAME'] = (script_name + location)
|
84
|
+
env['PATH_INFO'] = rest
|
85
|
+
|
86
|
+
return app.call(env)
|
87
|
+
end
|
88
|
+
|
89
|
+
[404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]
|
90
|
+
|
91
|
+
ensure
|
92
|
+
env['PATH_INFO'] = path
|
93
|
+
env['SCRIPT_NAME'] = script_name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: circuit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maxmedia
|
9
|
+
- Blake Chambers
|
10
|
+
- Travis D. Warlick, Jr.
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rack
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.3'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '1.3'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: activesupport
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activemodel
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.1'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.1'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: dionysus
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.0.0
|
72
|
+
type: :runtime
|
73
|
+
prerelease: false
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.0.0
|
80
|
+
description: ! 'Circuit is a rack application middleware that enables dynamic request
|
81
|
+
mapping. Modeled after [Rack::Builder](https://github.com/rack/rack/blob/master/lib/rack/builder.rb),
|
82
|
+
Circuit provides for a tree of url-mappings that is walked at request time. If
|
83
|
+
you are interested in dynamically loading middleware and functionality into requests,
|
84
|
+
circuit is a viable solution to do that in a maintainable way. '
|
85
|
+
email:
|
86
|
+
- it@maxmedia.com
|
87
|
+
- chambb1@gmail.com
|
88
|
+
- twarlick@gmail.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files:
|
92
|
+
- README.md
|
93
|
+
- LICENSE
|
94
|
+
- docs/COMPATIBILITY.md
|
95
|
+
- docs/ROADMAP.md
|
96
|
+
files:
|
97
|
+
- lib/circuit/behavior.rb
|
98
|
+
- lib/circuit/compatibility.rb
|
99
|
+
- lib/circuit/middleware/rewriter.rb
|
100
|
+
- lib/circuit/middleware.rb
|
101
|
+
- lib/circuit/rack/behavioral.rb
|
102
|
+
- lib/circuit/rack/builder.rb
|
103
|
+
- lib/circuit/rack/multi_site.rb
|
104
|
+
- lib/circuit/rack/request.rb
|
105
|
+
- lib/circuit/rack.rb
|
106
|
+
- lib/circuit/railtie.rb
|
107
|
+
- lib/circuit/storage/memory_model.rb
|
108
|
+
- lib/circuit/storage/nodes/memory_store.rb
|
109
|
+
- lib/circuit/storage/nodes/model.rb
|
110
|
+
- lib/circuit/storage/nodes/mongoid_store.rb
|
111
|
+
- lib/circuit/storage/nodes.rb
|
112
|
+
- lib/circuit/storage/sites/memory_store.rb
|
113
|
+
- lib/circuit/storage/sites/model.rb
|
114
|
+
- lib/circuit/storage/sites/mongoid_store.rb
|
115
|
+
- lib/circuit/storage/sites.rb
|
116
|
+
- lib/circuit/storage.rb
|
117
|
+
- lib/circuit/validators.rb
|
118
|
+
- lib/circuit/version.rb
|
119
|
+
- lib/circuit.rb
|
120
|
+
- vendor/active_support-3.2/core_ext/string/inflections.rb
|
121
|
+
- vendor/active_support-3.2/inflector/methods.rb
|
122
|
+
- vendor/rack-1.4/builder.rb
|
123
|
+
- vendor/rack-1.4/urlmap.rb
|
124
|
+
- config.ru
|
125
|
+
- Gemfile
|
126
|
+
- Rakefile
|
127
|
+
- description.md
|
128
|
+
- README.md
|
129
|
+
- LICENSE
|
130
|
+
- docs/COMPATIBILITY.md
|
131
|
+
- docs/ROADMAP.md
|
132
|
+
- spec/internal/app/behaviors/change_path.rb
|
133
|
+
- spec/internal/app/controllers/application_controller.rb
|
134
|
+
- spec/internal/app/helpers/application_helper.rb
|
135
|
+
- spec/internal/config/initializers/circuit.rb
|
136
|
+
- spec/internal/config/routes.rb
|
137
|
+
- spec/internal/db/schema.rb
|
138
|
+
- spec/lib/circuit/behavior_spec.rb
|
139
|
+
- spec/lib/circuit/middleware/rewriter_spec.rb
|
140
|
+
- spec/lib/circuit/rack/behavioral_spec.rb
|
141
|
+
- spec/lib/circuit/rack/builder_spec.rb
|
142
|
+
- spec/lib/circuit/rack/multi_site_spec.rb
|
143
|
+
- spec/lib/circuit/rack/request_spec.rb
|
144
|
+
- spec/lib/circuit/railtie_spec.rb
|
145
|
+
- spec/lib/circuit/storage/nodes_spec.rb
|
146
|
+
- spec/lib/circuit/storage/sites_spec.rb
|
147
|
+
- spec/lib/circuit/storage_spec.rb
|
148
|
+
- spec/lib/circuit/validators_spec.rb
|
149
|
+
- spec/lib/circuit_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- spec/support/blueprints.rb
|
152
|
+
- spec/support/matchers/be_current_time_matcher.rb
|
153
|
+
- spec/support/matchers/extended_have_key.rb
|
154
|
+
- spec/support/matchers/have_accessor_matcher.rb
|
155
|
+
- spec/support/matchers/have_attribute_matcher.rb
|
156
|
+
- spec/support/matchers/have_block_matcher.rb
|
157
|
+
- spec/support/matchers/have_errors_on_matcher.rb
|
158
|
+
- spec/support/matchers/have_module_matcher.rb
|
159
|
+
- spec/support/matchers/have_reader_matcher.rb
|
160
|
+
- spec/support/matchers/have_writer_matcher.rb
|
161
|
+
- spec/support/matchers/set_instance_variable.rb
|
162
|
+
- spec/support/spec_helpers/base_behaviors.rb
|
163
|
+
- spec/support/spec_helpers/base_models.rb
|
164
|
+
- spec/support/spec_helpers/logger_helpers.rb
|
165
|
+
- spec/support/spec_helpers/multi_site_helper.rb
|
166
|
+
- spec/support/spec_helpers/rack_helpers.rb
|
167
|
+
- spec/support/spec_helpers/shared_examples/node_store.rb
|
168
|
+
- spec/support/spec_helpers/shared_examples/site_store.rb
|
169
|
+
- spec/support/spec_helpers/simple_machinable.rb
|
170
|
+
- spec/support/spec_helpers/stores_cleaner.rb
|
171
|
+
homepage: http://github.com/maxmedia/circuit
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options:
|
176
|
+
- --main
|
177
|
+
- README.md
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: 1.8.7
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
188
|
+
requirements:
|
189
|
+
- - ! '>='
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 1.8.24
|
195
|
+
signing_key:
|
196
|
+
specification_version: 3
|
197
|
+
summary: Dynamic (backend-driven) request routing for Rack
|
198
|
+
test_files:
|
199
|
+
- spec/internal/app/behaviors/change_path.rb
|
200
|
+
- spec/internal/app/controllers/application_controller.rb
|
201
|
+
- spec/internal/app/helpers/application_helper.rb
|
202
|
+
- spec/internal/config/initializers/circuit.rb
|
203
|
+
- spec/internal/config/routes.rb
|
204
|
+
- spec/internal/db/schema.rb
|
205
|
+
- spec/lib/circuit/behavior_spec.rb
|
206
|
+
- spec/lib/circuit/middleware/rewriter_spec.rb
|
207
|
+
- spec/lib/circuit/rack/behavioral_spec.rb
|
208
|
+
- spec/lib/circuit/rack/builder_spec.rb
|
209
|
+
- spec/lib/circuit/rack/multi_site_spec.rb
|
210
|
+
- spec/lib/circuit/rack/request_spec.rb
|
211
|
+
- spec/lib/circuit/railtie_spec.rb
|
212
|
+
- spec/lib/circuit/storage/nodes_spec.rb
|
213
|
+
- spec/lib/circuit/storage/sites_spec.rb
|
214
|
+
- spec/lib/circuit/storage_spec.rb
|
215
|
+
- spec/lib/circuit/validators_spec.rb
|
216
|
+
- spec/lib/circuit_spec.rb
|
217
|
+
- spec/spec_helper.rb
|
218
|
+
- spec/support/blueprints.rb
|
219
|
+
- spec/support/matchers/be_current_time_matcher.rb
|
220
|
+
- spec/support/matchers/extended_have_key.rb
|
221
|
+
- spec/support/matchers/have_accessor_matcher.rb
|
222
|
+
- spec/support/matchers/have_attribute_matcher.rb
|
223
|
+
- spec/support/matchers/have_block_matcher.rb
|
224
|
+
- spec/support/matchers/have_errors_on_matcher.rb
|
225
|
+
- spec/support/matchers/have_module_matcher.rb
|
226
|
+
- spec/support/matchers/have_reader_matcher.rb
|
227
|
+
- spec/support/matchers/have_writer_matcher.rb
|
228
|
+
- spec/support/matchers/set_instance_variable.rb
|
229
|
+
- spec/support/spec_helpers/base_behaviors.rb
|
230
|
+
- spec/support/spec_helpers/base_models.rb
|
231
|
+
- spec/support/spec_helpers/logger_helpers.rb
|
232
|
+
- spec/support/spec_helpers/multi_site_helper.rb
|
233
|
+
- spec/support/spec_helpers/rack_helpers.rb
|
234
|
+
- spec/support/spec_helpers/shared_examples/node_store.rb
|
235
|
+
- spec/support/spec_helpers/shared_examples/site_store.rb
|
236
|
+
- spec/support/spec_helpers/simple_machinable.rb
|
237
|
+
- spec/support/spec_helpers/stores_cleaner.rb
|
238
|
+
has_rdoc:
|