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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80d38e94872ec129213f3efa13dd6f267d9828bac56263e1072773a961780068
4
- data.tar.gz: 1e57df88dca6335f9991c495a19ccb85d6a5b9cfd867201611d097680a756642
3
+ metadata.gz: 79d17b4bbd17aac6236afe083ccb7c47fc3257343f0a29b5e354bdd52f94a42d
4
+ data.tar.gz: fedca6223a916eb894fd18d9a1ed4bdf35edad809bc46b099bff138ce253e21d
5
5
  SHA512:
6
- metadata.gz: df112e100ee82c599b1ba0b89ec9a641cdd2880ec48c94ce52320102ae00209e9c9e927a067fd370a2800f3ee60d8f1717355a13515a8c9e04cb86016b2a2f83
7
- data.tar.gz: 0d2dc015025474fad3fc724f49ff93c16f8b103874944a05ad9fefa5117179b982997fd4891eb1667944ed82fdf9147b9daa2697e24d4c21e8049cef30e3afda
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 manifest_hash(root_path)[file]
7
- "#{ENV['CDN_URL']}#{root_path}/assets/#{manifest_hash(root_path)[file]}"
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']}#{root_path}/assets/#{file}"
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']}#{root_path}/assets/#{file}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdn_asset_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Baker