cdn_asset_gem 1.0.10 → 1.0.11
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 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79d17b4bbd17aac6236afe083ccb7c47fc3257343f0a29b5e354bdd52f94a42d
|
4
|
+
data.tar.gz: fedca6223a916eb894fd18d9a1ed4bdf35edad809bc46b099bff138ce253e21d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a28cd6084249a032f061de254462f21c1e219dea0d18b29b2dd4bf77efc15ca564d8e31615263d60a4d685fda67420b9e013f7754b17919dbe5560673b8e4acf
|
7
|
+
data.tar.gz: dba0e6a4f7240043302bc3415a1611d008586bfbbaee54560a5a305dba9462672167c786f74e87f8019decdedd778879f3b3ca5af6c03b66e1c8521c9fdd1905
|
@@ -3,29 +3,30 @@ module CdnAssetGem
|
|
3
3
|
module Helpers
|
4
4
|
def map_asset(root_path: '', asset_name:, file_type:)
|
5
5
|
file = "#{file_type}/#{asset_name}.min.#{file_type}"
|
6
|
-
if
|
7
|
-
|
6
|
+
assets_path = if root_path.blank? || root_path == '/'
|
7
|
+
'/assets'
|
8
|
+
else
|
9
|
+
"#{root_path}/assets"
|
10
|
+
end
|
11
|
+
manifest_hash = Rails.cache.fetch("cdn-asset-#{root_path}-#{asset_name}", expires_in: 5.minutes) do
|
12
|
+
uri = URI("#{ENV['CDN_URL']}#{assets_path}/rev-manifest.json")
|
13
|
+
response = HTTP.get(uri)
|
14
|
+
Rails.logger.info "CdnAssetGem INFO: uri: #{uri}"
|
15
|
+
Rails.logger.info "CdnAssetGem INFO: response #{response}"
|
16
|
+
if response.code == '200'
|
17
|
+
JSON.parse(response)
|
18
|
+
else
|
19
|
+
JSON.parse({})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
if manifest_hash[file]
|
23
|
+
"#{ENV['CDN_URL']}#{assets_path}/#{manifest_hash(root_path)[file]}"
|
8
24
|
else
|
9
|
-
"#{ENV['CDN_URL']}#{
|
25
|
+
"#{ENV['CDN_URL']}#{assets_path}/#{file}"
|
10
26
|
end
|
11
27
|
resuce StandardError => e
|
12
28
|
Rails.logger.error "CdnAssetGem Error: #{e}"
|
13
|
-
"#{ENV['CDN_URL']}#{
|
14
|
-
end
|
15
|
-
|
16
|
-
def manifest_hash(root_path)
|
17
|
-
if root_path.blank? || root_path == '/'
|
18
|
-
assets_path = '/assets'
|
19
|
-
else
|
20
|
-
assets_path = "#{root_path}/assets"
|
21
|
-
end
|
22
|
-
|
23
|
-
Rails.cache.fetch("cdn-asset-#{root_path}", expires_in: 5.minutes) do
|
24
|
-
uri = URI("#{ENV['CDN_URL']}#{assets_path}/rev-manifest.json")
|
25
|
-
response = HTTP.get(uri)
|
26
|
-
Rails.logger.info "CdnAssetGem INFO: #{response}"
|
27
|
-
JSON.parse(response) if response.code == '200'
|
28
|
-
end
|
29
|
+
"#{ENV['CDN_URL']}#{assets_path}/#{file}"
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|