wayfarer-jruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/_includes/navigation.html +5 -0
- data/docs/_layouts/default.html +1 -1
- data/docs/routing/filetypes_rules.md +21 -0
- data/lib/wayfarer.rb +2 -1
- data/lib/wayfarer/job.rb +9 -1
- data/lib/wayfarer/routing/filetypes_rule.rb +20 -0
- data/lib/wayfarer/routing/rule.rb +4 -0
- data/spec/job_spec.rb +12 -0
- data/spec/routing/filetypes_rule_spec.rb +40 -0
- data/spec/routing/rule_spec.rb +11 -0
- data/wayfarer-jruby.gemspec +1 -1
- data/wayfarer.gemspec +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a9a69bfbbda65a5e38bc9354f4a748257ad7aab
|
4
|
+
data.tar.gz: a82bf0193ef66897008c3921b2f20c3655ff6556
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00a9858095e9db1f5ab535fa6d3501e990def78024ea9c561edcdcf0fef8d60821c18ad20e74f190c203f05bcc93ab40fa3f50179e65004e75aa31e5c9c09dc2
|
7
|
+
data.tar.gz: 80e2e9300198604248a0286f9bd4723d21351794c44fc75e2fabfde3001380c4c348b22949da23a2748a00aceeb42dd8b2e90e5d3d8ffb47f36f35a4f06b7e94
|
@@ -110,6 +110,11 @@
|
|
110
110
|
Protocol rules
|
111
111
|
</a>
|
112
112
|
</li>
|
113
|
+
<li class="navigation__page">
|
114
|
+
<a class="navigation__link" href="{{base}}/routing/filetypes_rules.html">
|
115
|
+
Filetypes rules
|
116
|
+
</a>
|
117
|
+
</li>
|
113
118
|
<li class="navigation__page">
|
114
119
|
<a class="navigation__link" href="{{base}}/routing/custom_rules.html">
|
115
120
|
Custom rules
|
data/docs/_layouts/default.html
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
layout: default
|
3
|
+
title: Filetypes rules
|
4
|
+
---
|
5
|
+
|
6
|
+
# Filetypes rules
|
7
|
+
|
8
|
+
Filetypes rules match against the URI path's file extension.
|
9
|
+
|
10
|
+
{% highlight ruby %}
|
11
|
+
class DummyJob < Wayfarer::Job
|
12
|
+
route.filetypes [:png, :jpg], to: :image
|
13
|
+
route.forbid.filetypes [:php, :js]
|
14
|
+
end
|
15
|
+
{% endhighlight %}
|
16
|
+
|
17
|
+
Matches:
|
18
|
+
|
19
|
+
* `http://example.com/foo.png`
|
20
|
+
* `http://example.com/foo.jpg`
|
21
|
+
* `https://example.com/qux/bar.jpg`
|
data/lib/wayfarer.rb
CHANGED
@@ -14,6 +14,7 @@ require_relative "wayfarer/routing/host_rule"
|
|
14
14
|
require_relative "wayfarer/routing/path_rule"
|
15
15
|
require_relative "wayfarer/routing/query_rule"
|
16
16
|
require_relative "wayfarer/routing/protocol_rule"
|
17
|
+
require_relative "wayfarer/routing/filetypes_rule"
|
17
18
|
require_relative "wayfarer/routing/custom_rule"
|
18
19
|
require_relative "wayfarer/routing/router"
|
19
20
|
|
@@ -49,7 +50,7 @@ require_relative "wayfarer/dispatcher"
|
|
49
50
|
require_relative "wayfarer/processor"
|
50
51
|
|
51
52
|
module Wayfarer
|
52
|
-
VERSION = "0.0.
|
53
|
+
VERSION = "0.0.3"
|
53
54
|
|
54
55
|
def self.logger
|
55
56
|
return @logger if @logger
|
data/lib/wayfarer/job.rb
CHANGED
@@ -159,7 +159,15 @@ module Wayfarer
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
-
|
162
|
+
# This method has somewhat become the guard keeper for invalid URIs that
|
163
|
+
# would lead to exceptions otherwise down the line
|
164
|
+
supported = expanded.select do |uri|
|
165
|
+
HTTPAdapters::NetHTTPAdapter::RECOGNIZED_URI_TYPES.any? do |type|
|
166
|
+
uri.is_a?(type)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
@staged_uris.push(*supported)
|
163
171
|
end
|
164
172
|
|
165
173
|
# The {Page} representing the URI currently processed by an action.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Wayfarer
|
5
|
+
module Routing
|
6
|
+
# @private
|
7
|
+
class FiletypesRule < Rule
|
8
|
+
def initialize(types, opts = {}, &proc)
|
9
|
+
@types = types
|
10
|
+
super(opts, &proc)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def match!(uri)
|
16
|
+
@types.any? { |type| uri.path =~ /\.#{type}$/ }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/job_spec.rb
CHANGED
@@ -106,5 +106,17 @@ describe Wayfarer::Job do
|
|
106
106
|
job_instance.send(:stage, *uris)
|
107
107
|
}.to change { job_instance.staged_uris }.from([]).to(expected)
|
108
108
|
end
|
109
|
+
|
110
|
+
context "with non-HTTP(s) URIs" do
|
111
|
+
it "ignores them and does not raise an exception" do
|
112
|
+
job_instance = job.new
|
113
|
+
|
114
|
+
expect {
|
115
|
+
job_instance.send(:stage, "ftp://example.com")
|
116
|
+
}.not_to raise_error
|
117
|
+
|
118
|
+
expect(job_instance.staged_uris).to be_empty
|
119
|
+
end
|
120
|
+
end
|
109
121
|
end
|
110
122
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helpers"
|
3
|
+
|
4
|
+
describe Wayfarer::Routing::FiletypesRule do
|
5
|
+
subject(:rule) { FiletypesRule.new([:png, :js]) }
|
6
|
+
|
7
|
+
describe "#matches?" do
|
8
|
+
context "with matching URI" do
|
9
|
+
it "returns true" do
|
10
|
+
uris = %w(
|
11
|
+
http://example.com/foo.png
|
12
|
+
https://example.com/a/b.png/c.png
|
13
|
+
http://example.com/foobar.html.png
|
14
|
+
https://example.com/foo.png/bar.png
|
15
|
+
).map { |u| URI(u) }
|
16
|
+
|
17
|
+
uris.each do |uri|
|
18
|
+
expect(rule.matches?(uri)).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with mismatching URI" do
|
24
|
+
it "returns false" do
|
25
|
+
uris = %w(
|
26
|
+
http://example.png
|
27
|
+
http://example.com.png
|
28
|
+
https://example.com/a/b.png/c
|
29
|
+
http://example.com.html
|
30
|
+
http://example.com/foobar.html
|
31
|
+
https://example.com/foo.png/bar.png.html
|
32
|
+
).map { |u| URI(u) }
|
33
|
+
|
34
|
+
uris.each do |uri|
|
35
|
+
expect(rule.matches?(uri)).to be false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/routing/rule_spec.rb
CHANGED
@@ -190,6 +190,17 @@ describe Wayfarer::Routing::Rule do
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
+
describe "#filetypes" do
|
194
|
+
it "adds a FiletypesRule as a sub-rule" do
|
195
|
+
rule.filetypes [:png, :jpg]
|
196
|
+
expect(rule.child_rules.first).to be_a FiletypesRule
|
197
|
+
end
|
198
|
+
|
199
|
+
it "returns the added FiletypeRule" do
|
200
|
+
expect(rule.filetypes [:png]).to be_a FiletypesRule
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
193
204
|
describe "#build_child_rule_chain_from_options" do
|
194
205
|
subject(:rule) do
|
195
206
|
rule = Rule.new
|
data/wayfarer-jruby.gemspec
CHANGED
data/wayfarer.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wayfarer-jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominic Bauer
|
@@ -518,6 +518,7 @@ files:
|
|
518
518
|
- docs/recipes/multiple_uris.md
|
519
519
|
- docs/recipes/screenshots.md
|
520
520
|
- docs/routing/custom_rules.md
|
521
|
+
- docs/routing/filetypes_rules.md
|
521
522
|
- docs/routing/host_rules.md
|
522
523
|
- docs/routing/path_rules.md
|
523
524
|
- docs/routing/protocol_rules.md
|
@@ -549,6 +550,7 @@ files:
|
|
549
550
|
- lib/wayfarer/parsers/xml_parser.rb
|
550
551
|
- lib/wayfarer/processor.rb
|
551
552
|
- lib/wayfarer/routing/custom_rule.rb
|
553
|
+
- lib/wayfarer/routing/filetypes_rule.rb
|
552
554
|
- lib/wayfarer/routing/host_rule.rb
|
553
555
|
- lib/wayfarer/routing/path_rule.rb
|
554
556
|
- lib/wayfarer/routing/protocol_rule.rb
|
@@ -577,6 +579,7 @@ files:
|
|
577
579
|
- spec/parsers/xml_parser_spec.rb
|
578
580
|
- spec/processor_spec.rb
|
579
581
|
- spec/routing/custom_rule_spec.rb
|
582
|
+
- spec/routing/filetypes_rule_spec.rb
|
580
583
|
- spec/routing/host_rule_spec.rb
|
581
584
|
- spec/routing/path_rule_spec.rb
|
582
585
|
- spec/routing/protocol_rule_spec.rb
|