Class: Tapioca::Gemfile::GemSpec
- Inherits:
-
Object
- Object
- Tapioca::Gemfile::GemSpec
show all
- Extended by:
- T::Sig
- Includes:
- Tapioca::GemHelper
- Defined in:
- lib/tapioca/gemfile.rb
Constant Summary
collapse
- IGNORED_GEMS =
T.let(
[
"sorbet",
"sorbet-static",
"sorbet-runtime",
"sorbet-static-and-runtime",
"debug",
"fakefs",
].freeze,
T::Array[String],
)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#gem_in_app_dir?, #gem_in_bundle_path?, #gem_in_ruby_path?, #to_realpath
Constructor Details
#initialize(spec) ⇒ GemSpec
Returns a new instance of GemSpec.
135
136
137
138
139
140
141
142
|
# File 'lib/tapioca/gemfile.rb', line 135
def initialize(spec)
@spec = T.let(spec, Tapioca::Gemfile::Spec)
real_gem_path = to_realpath(@spec.full_gem_path)
@full_gem_path = T.let(real_gem_path, String)
@version = T.let(version_string, String)
@exported_rbi_files = T.let(nil, T.nilable(T::Array[String]))
@files = T.let(collect_files, T::Array[Pathname])
end
|
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
132
133
134
|
# File 'lib/tapioca/gemfile.rb', line 132
def files
@files
end
|
#full_gem_path ⇒ Object
Returns the value of attribute full_gem_path.
129
130
131
|
# File 'lib/tapioca/gemfile.rb', line 129
def full_gem_path
@full_gem_path
end
|
#version ⇒ Object
Returns the value of attribute version.
129
130
131
|
# File 'lib/tapioca/gemfile.rb', line 129
def version
@version
end
|
Class Method Details
.spec_lookup_by_file_path ⇒ Object
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/tapioca/gemfile.rb', line 104
def spec_lookup_by_file_path
@lookup ||= T.let(
[*::Gem::Specification.default_stubs, *::Gem::Specification.stubs]
.map! { |spec| new(spec.to_spec) }
.flat_map do |spec|
spec.files.filter_map { |file| [file.realpath.to_s, spec] if file.exist? }
end.to_h,
T.nilable(T::Hash[String, Gemfile::GemSpec]),
)
end
|
Instance Method Details
#==(other) ⇒ Object
145
146
147
|
# File 'lib/tapioca/gemfile.rb', line 145
def ==(other)
GemSpec === other && other.name == name && other.version == version
end
|
#contains_path?(path) ⇒ Boolean
165
166
167
168
169
170
171
|
# File 'lib/tapioca/gemfile.rb', line 165
def contains_path?(path)
if default_gem?
files.any? { |file| file.to_s == to_realpath(path) }
else
path_in_dir?(to_realpath(path), full_gem_path) || has_parent_gemspec?(path)
end
end
|
#export_rbi_files? ⇒ Boolean
184
185
186
|
# File 'lib/tapioca/gemfile.rb', line 184
def export_rbi_files?
exported_rbi_files.any?
end
|
#exported_rbi_files ⇒ Object
179
180
181
|
# File 'lib/tapioca/gemfile.rb', line 179
def exported_rbi_files
@exported_rbi_files ||= Dir.glob("#{full_gem_path}/rbi/**/*.rbi").sort
end
|
#exported_rbi_tree ⇒ Object
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/tapioca/gemfile.rb', line 189
def exported_rbi_tree
rewriter = RBI::Rewriters::Merge.new(keep: RBI::Rewriters::Merge::Keep::NONE)
exported_rbi_files.each do |file|
rbi = RBI::Parser.parse_file(file)
rewriter.merge(rbi)
end
rewriter.tree
end
|
#ignore?(gemfile_dir) ⇒ Boolean
150
151
152
|
# File 'lib/tapioca/gemfile.rb', line 150
def ignore?(gemfile_dir)
gem_ignored? || gem_in_app_dir?(gemfile_dir, full_gem_path)
end
|
#name ⇒ Object
155
156
157
|
# File 'lib/tapioca/gemfile.rb', line 155
def name
@spec.name
end
|
#parse_yard_docs ⇒ Object
174
175
176
|
# File 'lib/tapioca/gemfile.rb', line 174
def parse_yard_docs
files.each { |path| YARD.parse(path.to_s, [], Logger::Severity::FATAL) }
end
|
#rbi_file_name ⇒ Object
160
161
162
|
# File 'lib/tapioca/gemfile.rb', line 160
def rbi_file_name
"#{name}@#{version}.rbi"
end
|
#relative_path_for(file) ⇒ Object
201
202
203
204
205
206
207
|
# File 'lib/tapioca/gemfile.rb', line 201
def relative_path_for(file)
if default_gem?
file.realpath.relative_path_from(RbConfig::CONFIG["rubylibdir"])
else
file.realpath.relative_path_from(full_gem_path)
end
end
|