packs 0.0.44 → 0.0.45

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: 3409cd21dc5284518fa90923038c0dee964186909b2934445ae0872d97b2c101
4
- data.tar.gz: 9bac9fc2170f7aeaa52e4b141dd37cfcf19fb7c3577a80e29d49cfb07dfd229b
3
+ metadata.gz: ad12cf46cbfafc5f4b3b2d785f2ec2f3f67ed34cb8322bba6929a7ae584d06e1
4
+ data.tar.gz: 8712c08b31b3457b403d3814764496f3c4d46e53867f88760cadd10083e38a63
5
5
  SHA512:
6
- metadata.gz: 40891c45799b1d861ac76794f3645250c213d217c3b92178af89bb07f519b4fe13ee1650efb693c9a1d859742860dc32ee1ceca7bdedeffb593bd951b25ec5de
7
- data.tar.gz: 3a212158f68da47f7a38ca60b16193ba72cdceb319c302aca547eae49f4a351d379cbe8d334703a4caf6d9c6fea4752a8959c76f18552fee9fda162069d635f9
6
+ metadata.gz: bad96e8500d53692f4930cb08ae0ed1be99b8b0524283027d424a05094d23039b5ed9bd646d94db4e67de158ca5af480288c05e799af0a82e6c46cc2c4190fc0
7
+ data.tar.gz: ed7ebf9ed287b16336187500dc1ebfb833ce569039f7ad9775e9cf84fee53be47f6326fd8b7a4f3abc61d922080dc9ae2ab8e3049583bf8165871b7a4e763ffb
@@ -53,15 +53,20 @@ module Packs
53
53
 
54
54
  sig { returns(FileMoveOperation) }
55
55
  def spec_file_move_operation
56
+ path_parts = filepath_without_pack_name.split('/')
57
+ folder = T.must(path_parts[0])
58
+ file_extension = T.must(filepath_without_pack_name.split('.').last)
59
+
56
60
  # This could probably be implemented by some "strategy pattern" where different extension types are handled by different helpers
57
61
  # Such a thing could also include, for example, when moving a controller, moving its ERB view too.
58
- if origin_pathname.extname == '.rake'
59
- new_origin_pathname = origin_pathname.sub('/lib/', '/spec/lib/').sub(%r{^lib/}, 'spec/lib/').sub('.rake', '_spec.rb')
60
- new_destination_pathname = destination_pathname.sub('/lib/', '/spec/lib/').sub(%r{^lib/}, 'spec/lib/').sub('.rake', '_spec.rb')
62
+ if folder == 'app'
63
+ new_origin_pathname = spec_pathname_for_app(origin_pathname, file_extension)
64
+ new_destination_pathname = spec_pathname_for_app(destination_pathname, file_extension)
61
65
  else
62
- new_origin_pathname = origin_pathname.sub('/app/', '/spec/').sub(%r{^app/}, 'spec/').sub('.rb', '_spec.rb')
63
- new_destination_pathname = destination_pathname.sub('/app/', '/spec/').sub(%r{^app/}, 'spec/').sub('.rb', '_spec.rb')
66
+ new_origin_pathname = spec_pathname_for_non_app(origin_pathname, file_extension, folder)
67
+ new_destination_pathname = spec_pathname_for_non_app(destination_pathname, file_extension, folder)
64
68
  end
69
+
65
70
  FileMoveOperation.new(
66
71
  origin_pathname: new_origin_pathname,
67
72
  destination_pathname: new_destination_pathname,
@@ -69,8 +74,38 @@ module Packs
69
74
  )
70
75
  end
71
76
 
77
+ sig { params(filepath: Pathname, pack: T.nilable(Packs::Pack)).returns(String) }
78
+ def self.get_filepath_without_pack_name(filepath, pack)
79
+ if pack
80
+ filepath.to_s.gsub("#{pack.name}/", '')
81
+ else
82
+ filepath.to_s
83
+ end
84
+ end
85
+
72
86
  private
73
87
 
88
+ sig { returns(String) }
89
+ def filepath_without_pack_name
90
+ self.class.get_filepath_without_pack_name(origin_pathname, origin_pack)
91
+ end
92
+
93
+ sig { params(pathname: Pathname, file_extension: String).returns(Pathname) }
94
+ def spec_pathname_for_app(pathname, file_extension)
95
+ pathname
96
+ .sub('/app/', '/spec/')
97
+ .sub(%r{^app/}, 'spec/')
98
+ .sub(".#{file_extension}", '_spec.rb')
99
+ end
100
+
101
+ sig { params(pathname: Pathname, file_extension: String, folder: String).returns(Pathname) }
102
+ def spec_pathname_for_non_app(pathname, file_extension, folder)
103
+ pathname
104
+ .sub("/#{folder}/", "/spec/#{folder}/")
105
+ .sub(%r{^#{folder}/}, "spec/#{folder}/")
106
+ .sub(".#{file_extension}", '_spec.rb')
107
+ end
108
+
74
109
  sig { params(path: Pathname).returns(FileMoveOperation) }
75
110
  def relative_to(path)
76
111
  FileMoveOperation.new(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-12 00:00:00.000000000 Z
11
+ date: 2024-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
344
  - !ruby/object:Gem::Version
345
345
  version: '0'
346
346
  requirements: []
347
- rubygems_version: 3.5.9
347
+ rubygems_version: 3.5.16
348
348
  signing_key:
349
349
  specification_version: 4
350
350
  summary: Provides CLI tools for working with ruby packs.