cdn_asset_gem 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cdn_asset_gem/view/helpers.rb +20 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14c2591db7fdc3a6386d21abd13c5c97fcb6e26d
|
4
|
+
data.tar.gz: c3bfc7dcdd4c61e6d3acc26217d64a20661e08bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffdde89016e4527a21e4cd446a34003f0420b37bd48ed0d7ed204ac0997bbc7893d0e192d38d5f354e07cb8aa6e556332fefa3b0d61e228cba61cbb7b41e74fb
|
7
|
+
data.tar.gz: 315c6dd7790cb0d61aa18fa130f7d50c93145bc0e6fcc57df0661d2779bd9a976f10bfbd5ed842829026f88dfad7cc5c58fe33b8bb9ae038a6fcc325f73efa66
|
@@ -1,30 +1,28 @@
|
|
1
1
|
module CdnAssetGem
|
2
|
-
|
3
|
-
|
4
|
-
def map_asset(root_path: '', asset_name:, file_type:)
|
5
|
-
file = "#{file_type}/#{asset_name}.min.#{file_type}"
|
2
|
+
def map_asset(root_path: '', asset_name:, file_type:)
|
3
|
+
file = "#{file_type}/#{asset_name}.min.#{file_type}"
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
if manifest_hash(root_path)[file]
|
6
|
+
"#{ENV['CDN_URL']}#{root_path}/assets/#{manifest_hash(root_path)[file]}"
|
7
|
+
else
|
8
|
+
"#{ENV['CDN_URL']}#{root_path}/assets/#{file}"
|
9
|
+
end
|
10
|
+
end
|
13
11
|
|
14
|
-
|
12
|
+
private
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def manifest_hash(root_path)
|
15
|
+
if root_path.blank? || root_path == '/'
|
16
|
+
assets_path = '/assets'
|
17
|
+
else
|
18
|
+
assets_path = "#{root_path}/assets"
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
Rails.cache.fetch("cdn-asset-#{root_path}", expires_in: 5.minutes) do
|
22
|
+
uri = URI("#{ENV['CDN_URL']}#{assets_path}/rev-manifest.json")
|
23
|
+
response = Net::HTTP.get(uri)
|
24
|
+
response_code = Net::HTTP.get_response(uri).code
|
25
|
+
JSON.parse(response) if response_code == '200'
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|