wayfarer 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: c99ff804578236db96766eecce89450d6e489f4d
|
4
|
+
data.tar.gz: 8340d4c0e55cb35c20fc688f6ac9badfb6b4a6cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10308569f8290771a7fce4e5b382c19103cd29671d539fc85917852e6194722ee9b8c8d49f08bc8034bf63f604b13a369fdfffb69ed67703ec3c2ca25d490352
|
7
|
+
data.tar.gz: 2726271b256bab8781267dd6851ba0fda6601fea2fae38f3ed7adf68c0ba64190d3da0fcb38cf4bc0de39a7c3ddfe3507c32714a2fbcc5fbf813659dbe0459bc
|
@@ -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
|
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
|
@@ -588,6 +588,7 @@ files:
|
|
588
588
|
- docs/recipes/multiple_uris.md
|
589
589
|
- docs/recipes/screenshots.md
|
590
590
|
- docs/routing/custom_rules.md
|
591
|
+
- docs/routing/filetypes_rules.md
|
591
592
|
- docs/routing/host_rules.md
|
592
593
|
- docs/routing/path_rules.md
|
593
594
|
- docs/routing/protocol_rules.md
|
@@ -619,6 +620,7 @@ files:
|
|
619
620
|
- lib/wayfarer/parsers/xml_parser.rb
|
620
621
|
- lib/wayfarer/processor.rb
|
621
622
|
- lib/wayfarer/routing/custom_rule.rb
|
623
|
+
- lib/wayfarer/routing/filetypes_rule.rb
|
622
624
|
- lib/wayfarer/routing/host_rule.rb
|
623
625
|
- lib/wayfarer/routing/path_rule.rb
|
624
626
|
- lib/wayfarer/routing/protocol_rule.rb
|
@@ -647,6 +649,7 @@ files:
|
|
647
649
|
- spec/parsers/xml_parser_spec.rb
|
648
650
|
- spec/processor_spec.rb
|
649
651
|
- spec/routing/custom_rule_spec.rb
|
652
|
+
- spec/routing/filetypes_rule_spec.rb
|
650
653
|
- spec/routing/host_rule_spec.rb
|
651
654
|
- spec/routing/path_rule_spec.rb
|
652
655
|
- spec/routing/protocol_rule_spec.rb
|