lib/tapioca/commands/dsl.rb in tapioca-0.10.5 vs lib/tapioca/commands/dsl.rb in tapioca-0.11.0
- old
+ new
@@ -8,10 +8,11 @@
include RBIFilesHelper
sig do
params(
requested_constants: T::Array[String],
+ requested_paths: T::Array[Pathname],
outpath: Pathname,
only: T::Array[String],
exclude: T::Array[String],
file_header: T::Boolean,
tapioca_path: String,
@@ -25,10 +26,11 @@
app_root: String,
).void
end
def initialize(
requested_constants:,
+ requested_paths:,
outpath:,
only:,
exclude:,
file_header:,
tapioca_path:,
@@ -40,10 +42,11 @@
gem_dir: DEFAULT_GEM_DIR,
rbi_formatter: DEFAULT_RBI_FORMATTER,
app_root: "."
)
@requested_constants = requested_constants
+ @requested_paths = requested_paths
@outpath = outpath
@only = only
@exclude = exclude
@file_header = file_header
@tapioca_path = tapioca_path
@@ -61,11 +64,11 @@
sig { void }
def list_compilers
Loaders::Dsl.load_application(
tapioca_path: @tapioca_path,
- eager_load: @requested_constants.empty?,
+ eager_load: @requested_constants.empty? && @requested_paths.empty?,
app_root: @app_root,
)
pipeline = create_pipeline
@@ -99,10 +102,19 @@
else
say("Compiling DSL RBI files...")
end
say("")
+ unless @requested_paths.empty?
+ constants_from_paths = Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a
+ if constants_from_paths.empty?
+ say_error("\nWarning: No constants found in: #{@requested_paths.map(&:to_s).join(", ")}", :yellow)
+ end
+
+ @requested_constants += constants_from_paths
+ end
+
outpath = @should_verify ? Pathname.new(Dir.mktmpdir) : @outpath
rbi_files_to_purge = existing_rbi_filenames(@requested_constants)
pipeline = create_pipeline
@@ -151,10 +163,11 @@
sig { returns(Tapioca::Dsl::Pipeline) }
def create_pipeline
Tapioca::Dsl::Pipeline.new(
requested_constants: constantize(@requested_constants),
+ requested_paths: @requested_paths,
requested_compilers: constantize_compilers(@only),
excluded_compilers: constantize_compilers(@exclude),
error_handler: ->(error) {
say_error(error, :bold, :red)
},
@@ -165,11 +178,12 @@
sig { params(requested_constants: T::Array[String], path: Pathname).returns(T::Set[Pathname]) }
def existing_rbi_filenames(requested_constants, path: @outpath)
filenames = if requested_constants.empty?
Pathname.glob(path / "**/*.rbi")
else
- requested_constants.map do |constant_name|
- dsl_rbi_filename(constant_name)
+ requested_constants.filter_map do |constant_name|
+ filename = dsl_rbi_filename(constant_name)
+ filename if File.exist?(filename)
end
end
filenames.to_set
end