metanorma-release 0.2.19 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd193b321dc862e5773523c57a82a37966b93a087cd6354486ad067b50d2b992
4
- data.tar.gz: 40f1dd74b4409040d1cd625477d0787b07f6fc29eed1e98c6210e4f229ce2464
3
+ metadata.gz: 01147610e009c11c2192cd56b2aed8fc731c2c002a9d6e35f91c61045197fcfe
4
+ data.tar.gz: 54e3c27c6e5f06a3c310a12e2e20e51080df1ffb3d577ec5a1f378904fc59fa6
5
5
  SHA512:
6
- metadata.gz: dc2f1951bded304c45d587a0b57ebc2d4946aae4633748f6008588a5aa764a99c20f7a04a3ef8b8eb0034ac605ff582106cc621592c20710c7c6d5e3ec2a9963
7
- data.tar.gz: 51c29d6cf3d483e33dca8c5a13bf4f4564e1f25077b306015ec0bc09cc77dde50382c3767d2fc76b346d794413ba8060af756f4a3b556ba4d26a49626d47385f
6
+ metadata.gz: 294bfaa8b3772c8a4507c4168638b2aff9b2466592494ea68ed31abae6f205f41d038e0c9c946f7405711345921f9c6ae27e809d659e5b9b4485acc38850f6ca
7
+ data.tar.gz: '058a98333e8ee3506d93ed85d95a61a2c4a8316f53cebc85d2824968031a92b1b003b9bcbfcce697c42405e9f8a7e4061b343609b22ae22f6beed885f594dbba'
@@ -99,6 +99,7 @@ module Metanorma
99
99
  topic: @config.topic,
100
100
  repos: @config.repos,
101
101
  token: @config.token,
102
+ cache_dir: @config.cache_dir,
102
103
  )
103
104
 
104
105
  metadata_filter = MetadataFilter.new(
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
4
+
3
5
  module Metanorma
4
6
  module Release
5
7
  module Platform
@@ -13,8 +15,9 @@ module Metanorma
13
15
  class ReleaseFetcher
14
16
  include Metanorma::Release::ReleaseFetcher
15
17
 
16
- def initialize(client:)
18
+ def initialize(client:, download_cache_dir: nil)
17
19
  @client = client
20
+ @download_cache_dir = download_cache_dir
18
21
  end
19
22
 
20
23
  def fetch(repo, etag: nil)
@@ -67,11 +70,28 @@ module Metanorma
67
70
  end
68
71
 
69
72
  def download_asset(url)
70
- @client.get(url, accept: "application/octet-stream")
73
+ cache_path = cache_file_path(url)
74
+ if cache_path && File.exist?(cache_path)
75
+ return File.binread(cache_path)
76
+ end
77
+
78
+ data = @client.get(url, accept: "application/octet-stream")
79
+ if cache_path && data
80
+ FileUtils.mkdir_p(File.dirname(cache_path))
81
+ File.binwrite(cache_path, data)
82
+ end
83
+ data
71
84
  rescue StandardError => e
72
85
  warn "Warning: Failed to download asset #{url}: #{e.message}"
73
86
  nil
74
87
  end
88
+
89
+ def cache_file_path(url)
90
+ return nil unless @download_cache_dir
91
+
92
+ hash = Digest::SHA256.hexdigest(url)
93
+ File.join(@download_cache_dir, hash)
94
+ end
75
95
  end
76
96
  end
77
97
  end
@@ -31,9 +31,12 @@ module Metanorma
31
31
  )
32
32
  end
33
33
 
34
+ download_cache = opts[:cache_dir] ? File.join(opts[:cache_dir], "downloads") : nil
35
+
34
36
  {
35
37
  discoverer: discoverer,
36
- fetcher: Platform::GitHub::ReleaseFetcher.new(client: client),
38
+ fetcher: Platform::GitHub::ReleaseFetcher.new(client: client,
39
+ download_cache_dir: download_cache),
37
40
  manifest_reader: Platform::GitHub::ManifestReader.new(client: client),
38
41
  }
39
42
  },
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Metanorma
4
4
  module Release
5
- VERSION = "0.2.19"
5
+ VERSION = "0.2.20"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.