jsonapi-resources-anchor 2.1.1 → 2.4.0

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: e34fe32b3b500608a9ca5a8b76d788e9d52529776617dc2adfe0b5fc9729227f
4
- data.tar.gz: 04be2113fb3fb89ba4c632be707c6eb1fb84384683894574b62419b9a5ef30fc
3
+ metadata.gz: 7705f2e1f8acafaccc8736065acbd8fd57ab8c3611f3bcc918181c88f5373440
4
+ data.tar.gz: 07b6f3e0be8553503fd50a502cb69b64aa6a8713e497380450c9ac8dddf4243e
5
5
  SHA512:
6
- metadata.gz: ddda9cf3dc36bf3bc8d8d4fc0f0b9e81d8890fc36d517766fe84e7a1b79d1c351ecbdf5a46cb2ab3ceccda4c3f6ab6efbd6e9bd46fb05015cefcd8252a136b27
7
- data.tar.gz: a190c28448ada445356f02a3a2eae69200f65b786744ab7394dae83070d1878ed7ab1efee7d04d18b902f478f3b32c3e7ac487210d7ae11d3acde924176a77f6
6
+ metadata.gz: ea87194a6711d851e59557d52a551d7173f409f1a8fc4f595b30580963554fe6a7669249a7e17c70c31abe70d3309a739f37b4af796f29ce4ec2c8419951eb07
7
+ data.tar.gz: a8bc795a3ed08c50806403c4273264c4ecac4ebab38eea26b4c5568cbeed412d97a4f6d73d3a68b8f1215c46f6fbdb5ba798d02041f6f044b879762599f79df1
@@ -158,7 +158,6 @@ module Anchor
158
158
  end
159
159
  end
160
160
 
161
- # rubocop:disable Layout/LineLength
162
161
  # @param rel [Relationship]
163
162
  # @param resource_klass [Anchor::Resource]
164
163
  # @param name [String, Symbol]
@@ -184,5 +183,4 @@ module Anchor
184
183
  wrapper.call(rel_type)
185
184
  end
186
185
  end
187
- # rubocop:enable Layout/LineLength
188
186
  end
@@ -8,28 +8,48 @@ module Anchor::TypeScript
8
8
  new(...).call
9
9
  end
10
10
 
11
- def initialize(generator:, folder_path:, force: false)
11
+ def initialize(generator:, folder_path:, force: false, trust_hash: true)
12
12
  @generator = generator
13
13
  @folder_path = folder_path
14
14
  @force = force
15
+ @trust_hash = trust_hash
15
16
  end
16
17
 
17
18
  def call
18
19
  FileUtils.mkdir_p(@folder_path)
19
20
  results = @generator.call
20
- results.each { |result| save_result(result) }
21
+ modified_files = results.filter_map { |result| save_result(result) }
22
+ save_sha
23
+ modified_files
21
24
  end
22
25
 
23
26
  private
24
27
 
28
+ def sha_hash_path
29
+ Rails.root.join(@folder_path, "hash.json")
30
+ end
31
+
32
+ def sha_hash
33
+ return @sha_hash if defined?(@sha_hash)
34
+
35
+ @sha_hash = File.exist?(sha_hash_path) ? JSON.parse(File.read(sha_hash_path)) : {}
36
+ end
37
+
38
+ def save_sha
39
+ File.open(sha_hash_path, "w") { |f| f.write(@generator.sha_hash.to_json) }
40
+ end
41
+
42
+ # @return [String, nil] file name of file that is written to. nil if not written to
25
43
  def save_result(result)
26
44
  path = Rails.root.join(@folder_path, result.name)
27
45
 
28
46
  if @force || !File.exist?(path)
29
47
  File.open(path, "w") { |f| f.write(result.text) }
30
- return
48
+ return result.name
31
49
  end
32
50
 
51
+ return if @trust_hash && sha_hash[result.name] == Digest::SHA256.hexdigest(result.text)
52
+
33
53
  existing_content = File.read(path)
34
54
 
35
55
  new_content = if manually_editable?(existing_content)
@@ -42,6 +62,7 @@ module Anchor::TypeScript
42
62
  end
43
63
 
44
64
  File.open(path, "w") { |f| f.write(new_content) }
65
+ result.name
45
66
  end
46
67
 
47
68
  def manually_editable?(text)
@@ -24,7 +24,12 @@ module Anchor::TypeScript
24
24
  end
25
25
 
26
26
  def call
27
- [shared_file] + resource_files
27
+ @call ||= [shared_file] + resource_files
28
+ end
29
+
30
+ # { res.name => hash(res.text) }
31
+ def sha_hash
32
+ @sha_hash ||= call.map { |res| [res.name, Digest::SHA256.hexdigest(res.text)] }.to_h
28
33
  end
29
34
 
30
35
  private
@@ -1,8 +1,6 @@
1
1
  module Anchor::TypeScript
2
2
  class Serializer
3
3
  class << self
4
- # rubocop:disable Layout/LineLength
5
-
6
4
  def type_string(type, depth = 1)
7
5
  case type
8
6
  when Anchor::Types::String.singleton_class then "string"
@@ -23,7 +21,6 @@ module Anchor::TypeScript
23
21
  else raise RuntimeError
24
22
  end
25
23
  end
26
- # rubocop:enable Layout/LineLength
27
24
 
28
25
  private
29
26
 
@@ -1,8 +1,6 @@
1
1
  module Anchor::Types::Inference
2
2
  module ActiveRecord
3
3
  class << self
4
- # rubocop:disable Layout/LineLength
5
-
6
4
  # @return [Proc{Type => Type, Anchor::Types::Maybe<Type>, Anchor::Types::Array<Type>}]
7
5
  def wrapper_from_reflection(reflection)
8
6
  case reflection
@@ -14,7 +12,6 @@ module Anchor::Types::Inference
14
12
  else raise "#{reflection.class.name} not supported"
15
13
  end
16
14
  end
17
- # rubocop:enable Layout/LineLength
18
15
 
19
16
  private
20
17
 
@@ -1,3 +1,3 @@
1
1
  module Anchor
2
- VERSION = "2.1.1"
2
+ VERSION = "2.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources-anchor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-15 00:00:00.000000000 Z
11
+ date: 2025-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-resources