wayfarer 0.0.2 → 0.0.3

This diff has not been reviewed by any users.
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
2
  SHA1:
3
- metadata.gz: cfbc197a1369804ade3920254c0cadc0b7407cb8
4
- data.tar.gz: 94ed8f5f78858c334c727bf5de4b2f870129e436
3
+ metadata.gz: c99ff804578236db96766eecce89450d6e489f4d
4
+ data.tar.gz: 8340d4c0e55cb35c20fc688f6ac9badfb6b4a6cc
5
5
  SHA512:
6
- metadata.gz: 8777eeb4fbbafc3f9e423851afe196bc5a9b68d466c184138dad178d013002ead628a010635a4efea6fd1b50a8e2da1d0a8aa1a633877ab4b98e869ebb997459
7
- data.tar.gz: c1510f79a039cfbe6faf585689a5726f386249244dd8d932614bb4459f1a753aeed645b624d7e5ff4fc3d0e244f8cde8e17912c5d9feb6e2bf733d2b5c00f0de
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
@@ -11,7 +11,7 @@
11
11
  <a href="{{base}}" class="site-header__link">{{ site.title }}</a>
12
12
  </h1>
13
13
  <div class="site-header__version">
14
- 0.0.2
14
+ 0.0.3
15
15
  </div>
16
16
  </header>
17
17
 
@@ -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`
@@ -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.2"
53
+ VERSION = "0.0.3"
53
54
 
54
55
  def self.logger
55
56
  return @logger if @logger
@@ -159,7 +159,15 @@ module Wayfarer
159
159
  end
160
160
  end
161
161
 
162
- @staged_uris.push(*expanded)
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
@@ -87,6 +87,10 @@ module Wayfarer
87
87
  append_child_rule(CustomRule.new(*argv, &proc))
88
88
  end
89
89
 
90
+ def filetypes(*argv, &proc)
91
+ append_child_rule(FiletypesRule.new(*argv, &proc))
92
+ end
93
+
90
94
  private
91
95
 
92
96
  def append_child_rule(other)
@@ -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
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "wayfarer-jruby"
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
  s.license = "MIT"
7
7
 
8
8
  s.homepage = "http://github.com/bauerd/wayfarer"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "wayfarer"
4
- s.version = "0.0.2"
4
+ s.version = "0.0.3"
5
5
  s.license = "MIT"
6
6
 
7
7
  s.homepage = "http://github.com/bauerd/wayfarer"
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.2
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