lib/tapioca/helpers/gem_helper.rb in tapioca-0.10.1 vs lib/tapioca/helpers/gem_helper.rb in tapioca-0.10.2
- old
+ new
@@ -3,24 +3,36 @@
module Tapioca
module GemHelper
extend T::Sig
- sig { params(gemfile_dir: String, full_gem_path: String).returns(T::Boolean) }
- def gem_in_app_dir?(gemfile_dir, full_gem_path)
- !gem_in_bundle_path?(to_realpath(full_gem_path)) &&
- full_gem_path.start_with?(to_realpath(gemfile_dir))
+ sig { params(app_dir: String, full_gem_path: String).returns(T::Boolean) }
+ def gem_in_app_dir?(app_dir, full_gem_path)
+ app_dir = to_realpath(app_dir)
+ full_gem_path = to_realpath(full_gem_path)
+
+ !gem_in_bundle_path?(full_gem_path) && path_in_dir?(full_gem_path, app_dir)
end
sig { params(full_gem_path: String).returns(T::Boolean) }
def gem_in_bundle_path?(full_gem_path)
- full_gem_path.start_with?(Bundler.bundle_path.to_s, Bundler.app_cache.to_s)
+ path_in_dir?(full_gem_path, Bundler.bundle_path) || path_in_dir?(full_gem_path, Bundler.app_cache)
end
sig { params(path: T.any(String, Pathname)).returns(String) }
def to_realpath(path)
path_string = path.to_s
path_string = File.realpath(path_string) if File.exist?(path_string)
path_string
+ end
+
+ private
+
+ sig { params(path: T.any(Pathname, String), dir: T.any(Pathname, String)).returns(T::Boolean) }
+ def path_in_dir?(path, dir)
+ dir = Pathname.new(dir)
+ path = Pathname.new(path)
+
+ path.ascend.any?(dir)
end
end
end