Skip to content

Commit 979758d

Browse files
Refactor path for route
1 parent bdcbc59 commit 979758d

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

lib/critical_path_css/configuration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ def routes
2424
def penthouse_options
2525
@config['penthouse_options'] || {}
2626
end
27+
28+
def path_for_route(route)
29+
css_paths[routes.index(route)] || css_paths.first
30+
end
2731
end
2832
end

lib/critical_path_css/css_fetcher.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def fetch
1616
def fetch_route(route)
1717
options = {
1818
'url' => @config.base_url + route,
19-
'css' => fetch_css_path_for_route(route),
19+
'css' => @config.path_for_route(route),
2020
'width' => 1300,
2121
'height' => 900,
2222
'timeout' => 30_000,
@@ -51,17 +51,5 @@ def fetch_route(route)
5151
end
5252
out
5353
end
54-
55-
private
56-
57-
def fetch_css_path_for_route(route)
58-
index_for_route = @config.routes.index(route)
59-
60-
if index_for_route && @config.css_paths[index_for_route]
61-
@config.css_paths[index_for_route]
62-
else
63-
@config.css_path
64-
end
65-
end
6654
end
6755
end

spec/lib/critical_path_css/css_fetcher_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] }
88
let(:routes) { ['/', '/new_route'] }
99
let(:config) do
10-
OpenStruct.new(
11-
base_url: base_url,
12-
css_path: css_path,
13-
css_paths: css_paths,
14-
penthouse_options: {},
15-
routes: routes
10+
CriticalPathCss::Configuration.new(
11+
OpenStruct.new(
12+
base_url: base_url,
13+
css_paths: css_paths,
14+
penthouse_options: {},
15+
routes: routes
16+
)
1617
)
1718
end
1819

0 commit comments

Comments
 (0)