Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c04137c

Browse files
Minor refactor to config loader
1 parent 1f5d441 commit c04137c

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

‎lib/critical-path-css-rails.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ def self.fetch(route)
2828
end
2929

3030
def self.fetcher
31-
@fetcher ||= CssFetcher.new(Configuration.new(config))
31+
@fetcher ||= CssFetcher.new(Configuration.new(config_loader.config))
3232
end
3333

34-
def self.config
35-
@config ||= begin
36-
loader = CriticalPathCss::Rails::ConfigLoader.new
37-
loader.load
38-
loader.config
39-
end
34+
def self.config_loader
35+
@config_loader ||= CriticalPathCss::Rails::ConfigLoader.new
4036
end
4137
end

‎lib/critical_path_css/rails/config_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Rails
33
class ConfigLoader
44
CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze
55

6-
def load
6+
def initialize
77
validate_css_paths
88
format_css_paths
99
end

‎spec/lib/critical_path_css/rails/config_loader_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
CONFIG
2626
}
2727

28-
before do
29-
subject.load
30-
end
31-
3228
it 'sets css_path with the path' do
3329
expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css'
3430
end
@@ -58,10 +54,6 @@
5854
CONFIG
5955
}
6056

61-
before do
62-
subject.load
63-
end
64-
6557
it 'sets css_path to empty string' do
6658
expect(subject.config['css_path']).to eq ''
6759
end
@@ -93,7 +85,7 @@
9385
}
9486

9587
it 'raises an error' do
96-
expect { subject.load }.to raise_error LoadError, 'Cannot specify both css_path and css_paths'
88+
expect { subject }.to raise_error LoadError, 'Cannot specify both css_path and css_paths'
9789
end
9890
end
9991

@@ -119,7 +111,7 @@
119111
}
120112

121113
it 'raises an error' do
122-
expect { subject.load }.to raise_error LoadError, 'Must specify css_paths for each route'
114+
expect { subject }.to raise_error LoadError, 'Must specify css_paths for each route'
123115
end
124116
end
125117
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /