Skip to content

Commit

Permalink
Revert bb40f15 (#46)
Browse files Browse the repository at this point in the history
* Revert "for_class accepts string, remove unnecessary conversions (#39)"

This reverts commit bb40f15.

* bump version
  • Loading branch information
Alex Evanczuk authored Apr 7, 2023
1 parent e9f29ac commit 1fa1ac8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 47 deletions.
62 changes: 28 additions & 34 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
code_ownership (1.32.2)
code_ownership (1.32.3)
code_teams (~> 1.0)
packs
sorbet-runtime
Expand All @@ -13,19 +13,17 @@ GEM
code_teams (1.0.1)
sorbet-runtime
coderay (1.1.3)
diff-lcs (1.5.0)
diff-lcs (1.4.4)
method_source (1.0.0)
netrc (0.11.0)
packs (0.0.6)
sorbet-runtime
parallel (1.22.1)
parser (3.2.1.1)
parser (3.1.2.0)
ast (~> 2.4.1)
pry (0.14.2)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.6)
rbi (0.0.16)
rbi (0.0.14)
ast
parser (>= 2.6.4.0)
sorbet-runtime (>= 0.5.9204)
Expand All @@ -43,43 +41,39 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
sorbet (0.5.10707)
sorbet-static (= 0.5.10707)
sorbet-runtime (0.5.10707)
sorbet-static (0.5.10707-universal-darwin-14)
sorbet-static (0.5.10707-universal-darwin-15)
sorbet-static (0.5.10707-universal-darwin-16)
sorbet-static (0.5.10707-universal-darwin-17)
sorbet-static (0.5.10707-universal-darwin-18)
sorbet-static (0.5.10707-universal-darwin-19)
sorbet-static (0.5.10707-universal-darwin-20)
sorbet-static (0.5.10707-universal-darwin-21)
sorbet-static (0.5.10707-universal-darwin-22)
sorbet-static (0.5.10707-x86_64-linux)
sorbet-static-and-runtime (0.5.10707)
sorbet (= 0.5.10707)
sorbet-runtime (= 0.5.10707)
spoom (1.1.16)
sorbet (>= 0.5.10187)
sorbet (0.5.9889)
sorbet-static (= 0.5.9889)
sorbet-runtime (0.5.9889)
sorbet-static (0.5.9889-universal-darwin-14)
sorbet-static (0.5.9889-universal-darwin-15)
sorbet-static (0.5.9889-universal-darwin-16)
sorbet-static (0.5.9889-universal-darwin-17)
sorbet-static (0.5.9889-universal-darwin-18)
sorbet-static (0.5.9889-universal-darwin-19)
sorbet-static (0.5.9889-universal-darwin-20)
sorbet-static (0.5.9889-universal-darwin-21)
sorbet-static (0.5.9889-x86_64-linux)
spoom (1.1.11)
sorbet (>= 0.5.9204)
sorbet-runtime (>= 0.5.9204)
thor (>= 0.19.2)
tapioca (0.11.1)
tapioca (0.7.2)
bundler (>= 1.17.3)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (~> 0.0.0, >= 0.0.16)
sorbet-static-and-runtime (>= 0.5.10187)
pry (>= 0.12.2)
rbi (~> 0.0.0, >= 0.0.14)
sorbet-runtime (>= 0.5.9204)
sorbet-static (>= 0.5.9204)
spoom (~> 1.1.0, >= 1.1.11)
thor (>= 1.2.0)
yard-sorbet
thor (1.2.1)
unparser (0.6.7)
unparser (0.6.4)
diff-lcs (~> 1.3)
parser (>= 3.2.0)
parser (>= 3.1.0)
webrick (1.7.0)
yard (0.9.28)
yard (0.9.27)
webrick (~> 1.7.0)
yard-sorbet (0.8.0)
yard-sorbet (0.6.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)

Expand Down
2 changes: 1 addition & 1 deletion code_ownership.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "code_ownership"
spec.version = '1.32.2'
spec.version = '1.32.3'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'A gem to help engineering teams declare ownership of code'
Expand Down
13 changes: 5 additions & 8 deletions lib/code_ownership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,20 @@ def backtrace_with_ownership(backtrace)
end
private_class_method(:backtrace_with_ownership)

sig { params(klass: T.nilable(T.any(Class, Module, String))).returns(T.nilable(::CodeTeams::Team)) }
sig { params(klass: T.nilable(T.any(Class, Module))).returns(T.nilable(::CodeTeams::Team)) }
def for_class(klass)
@memoized_values ||= T.let(@memoized_values, T.nilable(T::Hash[String, T.nilable(::CodeTeams::Team)]))
@memoized_values ||= {}

klass_string = klass.to_s

# We use key because the memoized value could be `nil`
if !@memoized_values.key?(klass_string)
path = Private.path_from_klass_string(klass_string)
if !@memoized_values.key?(klass.to_s)
path = Private.path_from_klass(klass)
return nil if path.nil?

value_to_memoize = for_file(path)
@memoized_values[klass_string] = value_to_memoize
@memoized_values[klass.to_s] = value_to_memoize
value_to_memoize
else
@memoized_values[klass_string]
@memoized_values[klass.to_s]
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/code_ownership/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def self.validate!(files:, autocorrect: true, stage_changes: true)

# Returns a string version of the relative path to a Rails constant,
# or nil if it can't find something
sig { params(klass_string: T.nilable(String)).returns(T.nilable(String)) }
def self.path_from_klass_string(klass_string)
if klass_string
path = Object.const_source_location(klass_string)&.first
sig { params(klass: T.nilable(T.any(Class, Module))).returns(T.nilable(String)) }
def self.path_from_klass(klass)
if klass
path = Object.const_source_location(klass.to_s)&.first
(path && Pathname.new(path).relative_path_from(Pathname.pwd).to_s) || nil
else
nil
Expand Down

0 comments on commit 1fa1ac8

Please sign in to comment.