lib/packwerk/constant_discovery.rb in packwerk-2.3.0 vs lib/packwerk/constant_discovery.rb in packwerk-3.0.0
- old
+ new
@@ -1,6 +1,6 @@
-# typed: true
+# typed: strict
# frozen_string_literal: true
require "constant_resolver"
module Packwerk
@@ -15,12 +15,10 @@
# have no way of inferring the file it is defined in. You could argue though that inheritance means that another
# constant with the same name exists in the inheriting class, and this view is sufficient for all our use cases.
class ConstantDiscovery
extend T::Sig
- ConstantContext = Struct.new(:name, :location, :package, :public?)
-
# @param constant_resolver [ConstantResolver]
# @param packages [Packwerk::PackageSet]
sig do
params(constant_resolver: ConstantResolver, packages: Packwerk::PackageSet).void
end
@@ -48,16 +46,16 @@
# If the constant is unresolved, we need the current namespace path to correctly infer its full name
#
# @param const_name [String] The unresolved constant's name.
# @param current_namespace_path [Array<String>] (optional) The namespace of the context in which the constant is
# used, e.g. ["Apps", "Models"] for `Apps::Models`. Defaults to [] which means top level.
- # @return [Packwerk::ConstantDiscovery::ConstantContext]
+ # @return [ConstantContext]
sig do
params(
const_name: String,
current_namespace_path: T.nilable(T::Array[String]),
- ).returns(T.nilable(ConstantDiscovery::ConstantContext))
+ ).returns(T.nilable(ConstantContext))
end
def context_for(const_name, current_namespace_path: [])
begin
constant = @resolver.resolve(const_name, current_namespace_path: current_namespace_path)
rescue ConstantResolver::Error => e
@@ -69,10 +67,11 @@
package = @packages.package_from_path(constant.location)
ConstantContext.new(
constant.name,
constant.location,
package,
- package.public_path?(constant.location),
)
end
end
+
+ private_constant :ConstantDiscovery
end