Skip to content

Commit b8658d9

Browse files
committed
Refactor FixRedirectionsBehavior
1 parent 9c53ba1 commit b8658d9

4 files changed

Lines changed: 13 additions & 15 deletions

File tree

lib/docs/core/scraper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ def parse(string)
154154
Parser.new(string).html
155155
end
156156

157+
def with_filters(*filters)
158+
stack = FilterStack.new
159+
stack.push(*filters)
160+
pipeline.instance_variable_set :@filters, stack.to_a.freeze
161+
yield
162+
ensure
163+
@pipeline = nil
164+
end
165+
157166
module StubRootPage
158167
private
159168

lib/docs/core/scrapers/url_scraper.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ def self.included(base)
4242
end
4343

4444
module ClassMethods
45-
attr_accessor :fix_redirections
4645
attr_reader :redirections
4746

4847
def store_pages(store)
49-
return super unless fix_redirections
5048
instrument 'info.doc', msg: 'Fetching redirections...'
5149
with_redirections do
5250
instrument 'info.doc', msg: 'Building pages...'
@@ -84,17 +82,6 @@ def process_response(response)
8482
def additional_options
8583
{ redirections: self.class.redirections }
8684
end
87-
88-
def with_filters(*filters)
89-
stack = FilterStack.new
90-
stack.push(*filters)
91-
pipeline.instance_variable_set :@filters, stack.to_a.freeze
92-
yield
93-
ensure
94-
@pipeline = nil
95-
end
9685
end
97-
98-
include FixRedirectionsBehavior
9986
end
10087
end

lib/docs/scrapers/mdn/dom.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module Docs
22
class Dom < Mdn
3+
include FixRedirectionsBehavior
4+
35
self.name = 'DOM'
46
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/API'
5-
self.fix_redirections = true
67

78
html_filters.push 'dom/clean_html', 'dom/entries', 'title'
89

lib/docs/scrapers/mdn/svg.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module Docs
22
class Svg < Mdn
3+
include FixRedirectionsBehavior
4+
35
self.name = 'SVG'
46
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/SVG'
5-
self.fix_redirections = true
67

78
html_filters.push 'svg/clean_html', 'svg/entries', 'title'
89

0 commit comments

Comments
 (0)