Skip to content

Commit 7bab83d

Browse files
committed
add zeitwerk
1 parent 56e40d8 commit 7bab83d

File tree

14 files changed

+115
-41
lines changed

14 files changed

+115
-41
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
strategy:
1313
matrix:
1414
ruby:
15-
- 3.1
1615
- 3.2
1716
- 3.3
1817
- 3.4

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,4 @@ Style/HashSyntax:
120120

121121
Gemspec/DevelopmentDependencies:
122122
Enabled: true
123-
EnforcedStyle: gemspec
123+
EnforcedStyle: Gemfile

Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
source 'https://rubygems.org'
22

33
gemspec
4+
5+
gem 'debug'
6+
gem 'packwerk'
7+
gem 'railties'
8+
gem 'rake'
9+
gem 'rspec'
10+
gem 'rubocop'
11+
gem 'sorbet'
12+
gem 'tapioca'

code_ownership.gemspec

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,5 @@ Gem::Specification.new do |spec|
3030
spec.add_dependency 'code_teams', '~> 1.0'
3131
spec.add_dependency 'packs-specification'
3232
spec.add_dependency 'sorbet-runtime', '>= 0.5.11249'
33-
34-
spec.add_development_dependency 'debug'
35-
spec.add_development_dependency 'packwerk'
36-
spec.add_development_dependency 'railties'
37-
spec.add_development_dependency 'rake'
38-
spec.add_development_dependency 'rspec', '~> 3.0'
39-
spec.add_development_dependency 'rubocop'
40-
spec.add_development_dependency 'sorbet'
41-
spec.add_development_dependency 'tapioca'
33+
spec.add_dependency 'zeitwerk'
4234
end

lib/code_ownership.rb

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
# typed: strict
44

5-
require 'set'
65
require 'code_teams'
76
require 'sorbet-runtime'
87
require 'json'
98
require 'packs-specification'
10-
require 'code_ownership/mapper'
11-
require 'code_ownership/validator'
12-
require 'code_ownership/private'
13-
require 'code_ownership/cli'
14-
require 'code_ownership/configuration'
9+
require 'zeitwerk'
10+
11+
loader = Zeitwerk::Loader.for_gem
12+
loader.setup
1513

1614
if defined?(Packwerk)
17-
require 'code_ownership/private/permit_pack_owner_top_level_key'
15+
require 'code_ownership/private/pack_ownership_validator'
1816
end
1917

2018
module CodeOwnership
@@ -137,22 +135,22 @@ def backtrace_with_ownership(backtrace)
137135
# ./app/controllers/some_controller.rb:43:in `block (3 levels) in create'
138136
#
139137
backtrace_line = if RUBY_VERSION >= '3.4.0'
140-
%r{\A(#{Pathname.pwd}/|\./)?
141-
(?<file>.+) # Matches 'app/controllers/some_controller.rb'
142-
:
143-
(?<line>\d+) # Matches '43'
144-
:in\s
145-
'(?<function>.*)' # Matches "`block (3 levels) in create'"
146-
\z}x
147-
else
148-
%r{\A(#{Pathname.pwd}/|\./)?
149-
(?<file>.+) # Matches 'app/controllers/some_controller.rb'
150-
:
151-
(?<line>\d+) # Matches '43'
152-
:in\s
153-
`(?<function>.*)' # Matches "`block (3 levels) in create'"
154-
\z}x
155-
end
138+
%r{\A(#{Pathname.pwd}/|\./)?
139+
(?<file>.+) # Matches 'app/controllers/some_controller.rb'
140+
:
141+
(?<line>\d+) # Matches '43'
142+
:in\s
143+
'(?<function>.*)' # Matches "`block (3 levels) in create'"
144+
\z}x
145+
else
146+
%r{\A(#{Pathname.pwd}/|\./)?
147+
(?<file>.+) # Matches 'app/controllers/some_controller.rb'
148+
:
149+
(?<line>\d+) # Matches '43'
150+
:in\s
151+
`(?<function>.*)' # Matches "`block (3 levels) in create'"
152+
\z}x
153+
end
156154

157155
backtrace.lazy.filter_map do |line|
158156
match = line.match(backtrace_line)

lib/code_ownership/configuration.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module CodeOwnership
44
class Configuration < T::Struct
55
extend T::Sig
6+
67
DEFAULT_JS_PACKAGE_PATHS = T.let(['**/'], T::Array[String])
78

89
const :owned_globs, T::Array[String]
@@ -31,7 +32,7 @@ def self.fetch
3132
skip_codeowners_validation: config_hash.fetch('skip_codeowners_validation', false),
3233
raw_hash: config_hash,
3334
require_github_teams: config_hash.fetch('require_github_teams', false),
34-
codeowners_path: config_hash.fetch('codeowners_path', '.github'),
35+
codeowners_path: config_hash.fetch('codeowners_path', '.github')
3536
)
3637
end
3738

lib/code_ownership/private/extension_loader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Private
88
module ExtensionLoader
99
class << self
1010
extend T::Sig
11+
1112
sig { params(require_directive: String).void }
1213
def load(require_directive)
1314
# We want to transform the require directive to behave differently

lib/code_ownership/private/ownership_mappers/file_annotations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FileAnnotations
1818
extend T::Sig
1919
include Mapper
2020

21-
TEAM_PATTERN = T.let(%r{\A(?:#|//|-#) @team (?<team>.*)\Z}.freeze, Regexp)
21+
TEAM_PATTERN = T.let(%r{\A(?:#|//|-#) @team (?<team>.*)\Z}, Regexp)
2222
DESCRIPTION = 'Annotations at the top of file'
2323

2424
sig do

lib/code_ownership/private/ownership_mappers/team_globs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TeamGlobs
1717
returns(T::Hash[String, ::CodeTeams::Team])
1818
end
1919
def map_files_to_owners
20-
return @@map_files_to_owners if @@map_files_to_owners&.keys && @@map_files_to_owners.keys.count.positive?
20+
return @@map_files_to_owners if @@map_files_to_owners&.keys&.any?
2121

2222
@@map_files_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
2323
code_team = TeamPlugins::Ownership.for(team)

lib/code_ownership/private/ownership_mappers/team_yml_ownership.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TeamYmlOwnership
1717
.returns(T::Hash[String, ::CodeTeams::Team])
1818
end
1919
def map_files_to_owners(files)
20-
return @@map_files_to_owners if @@map_files_to_owners&.keys && @@map_files_to_owners.keys.count.positive?
20+
return @@map_files_to_owners if @@map_files_to_owners&.keys&.any?
2121

2222
@@map_files_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
2323
map[team.config_yml] = team

0 commit comments

Comments
 (0)