Class: Ryac::GemResolver
- Inherits:
-
Object
- Object
- Ryac::GemResolver
- Defined in:
- lib/ryac/gem_resolver.rb,
sig/ryac/gem_resolver.rbs
Defined Under Namespace
Classes: GemResolution
Class Method Summary collapse
-
.minifier_args(gem_names) ⇒ { entry: String | Array[String], project_root: Array[String], gem_require_paths: Array[String] }
The one spelling of "minify these installed gems": folds each gem's resolution into the Minifier#call keyword arguments, so the CLI and anything replicating it assemble the same invocation.
Instance Method Summary collapse
Class Method Details
.minifier_args(gem_names) ⇒ { entry: String | Array[String], project_root: Array[String], gem_require_paths: Array[String] }
The one spelling of "minify these installed gems": folds each gem's resolution into the Minifier#call keyword arguments, so the CLI and anything replicating it assemble the same invocation.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ryac/gem_resolver.rb', line 10 def self.minifier_args(gem_names) resolver = new resolutions = gem_names.map { |name| resolver.call(name) } entry = resolutions.map(&:entry_path) entry = entry[0] if entry.size == 1 { entry: entry, project_root: resolutions.map(&:project_root), gem_require_paths: resolutions.flat_map(&:require_paths), } end |
Instance Method Details
#call(gem_name) ⇒ GemResolution
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ryac/gem_resolver.rb', line 22 def call(gem_name) spec = Gem::Specification.find_by_name(gem_name) entry_path = find_entry_file(spec, gem_name) raise Pipeline::GemNotFoundError.new(gem_name) unless entry_path GemResolution.new( entry_path: entry_path, project_root: spec.gem_dir, require_paths: spec.full_require_paths ) rescue Gem::MissingSpecError raise Pipeline::GemNotFoundError.new(gem_name) end |
#find_entry_file(spec, gem_name) ⇒ String?
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ryac/gem_resolver.rb', line 38 def find_entry_file(spec, gem_name) candidates = [ gem_name, # json gem_name.tr('-', '_'), # concurrent-ruby -> concurrent_ruby gem_name.tr('-', '/'), # unicode-display_width -> unicode/display_width ].uniq spec.full_require_paths.each do |dir| candidates.each do |name| path = File.join(dir, "#{name}.rb") return path if File.exist?(path) end end nil end |