wayfarer-jruby 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 295c1dd844209a188bfac6929bfc3085b8e757c2
4
- data.tar.gz: 94ed8f5f78858c334c727bf5de4b2f870129e436
3
+ metadata.gz: 3a9a69bfbbda65a5e38bc9354f4a748257ad7aab
4
+ data.tar.gz: a82bf0193ef66897008c3921b2f20c3655ff6556
5
5
  SHA512:
6
- metadata.gz: 31d3e3fc05ccec48e995eb05bc8207faf96efc907217ac75575d61f0a4f40eb8217b206df76d97d6897b6f2244b4cc3672e2687ead3b9bb8e74b098e8a926bcf
7
- data.tar.gz: c1510f79a039cfbe6faf585689a5726f386249244dd8d932614bb4459f1a753aeed645b624d7e5ff4fc3d0e244f8cde8e17912c5d9feb6e2bf733d2b5c00f0de
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
@@ -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-jruby
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
@@ -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