jsonapi-resources-anchor 2.1.1 → 2.3.1

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: 64e06b2f2987b17e1c8d55c09f986e8f077497e38bed1f16a34e78d5efe9416a
4
+ data.tar.gz: 821a574d6e0df1d77184ba94b8ed0664d6db2ea25bbff31a0cc7fa4c477220eb
5
5
  SHA512:
6
- metadata.gz: ddda9cf3dc36bf3bc8d8d4fc0f0b9e81d8890fc36d517766fe84e7a1b79d1c351ecbdf5a46cb2ab3ceccda4c3f6ab6efbd6e9bd46fb05015cefcd8252a136b27
7
- data.tar.gz: a190c28448ada445356f02a3a2eae69200f65b786744ab7394dae83070d1878ed7ab1efee7d04d18b902f478f3b32c3e7ac487210d7ae11d3acde924176a77f6
6
+ metadata.gz: f4bf643f1470c646a8b568dc81a17d392ad1db333ec704449497ca8210dfb81a87f78cc30071143e2be726c352fc2d2d6f4accf1fe5ff3d58f8bee5f4efd579c
7
+ data.tar.gz: '0381457aa5bcbb056ab9fb3ec2baf05f65504c54b0db2b7705bdcbb3490dd7b770997ff636a2a4dcbdda3443d97ffc0654a3fbdd4b3291c38ba87271f9dd3bdc'
@@ -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
@@ -17,19 +17,38 @@ module Anchor::TypeScript
17
17
  def call
18
18
  FileUtils.mkdir_p(@folder_path)
19
19
  results = @generator.call
20
- results.each { |result| save_result(result) }
20
+ modified_files = results.filter_map { |result| save_result(result) }
21
+ save_sha
22
+ modified_files
21
23
  end
22
24
 
23
25
  private
24
26
 
27
+ def sha_hash_path
28
+ Rails.root.join(@folder_path, "hash.json")
29
+ end
30
+
31
+ def sha_hash
32
+ return @sha_hash if defined?(@sha_hash)
33
+
34
+ @sha_hash = File.exist?(sha_hash_path) ? JSON.parse(File.read(sha_hash_path)) : {}
35
+ end
36
+
37
+ def save_sha
38
+ File.open(sha_hash_path, "w") { |f| f.write(@generator.sha_hash.to_json) }
39
+ end
40
+
41
+ # @return [String, nil] file name of file that is written to. nil if not written to
25
42
  def save_result(result)
26
43
  path = Rails.root.join(@folder_path, result.name)
27
44
 
28
45
  if @force || !File.exist?(path)
29
46
  File.open(path, "w") { |f| f.write(result.text) }
30
- return
47
+ return result.name
31
48
  end
32
49
 
50
+ return if sha_hash[result.name] == Digest::SHA256.hexdigest(result.text)
51
+
33
52
  existing_content = File.read(path)
34
53
 
35
54
  new_content = if manually_editable?(existing_content)
@@ -42,6 +61,7 @@ module Anchor::TypeScript
42
61
  end
43
62
 
44
63
  File.open(path, "w") { |f| f.write(new_content) }
64
+ result.name
45
65
  end
46
66
 
47
67
  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.3.1"
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.3.1
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-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-resources