Class: Tapioca::Gemfile::GemSpec

Inherits:
Object
  • Object
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

Instance Method Summary collapse

Methods included from Tapioca::GemHelper

#gem_in_app_dir?, #gem_in_bundle_path?, #to_realpath

Constructor Details

#initialize(spec) ⇒ GemSpec



154
155
156
157
158
159
160
161
# File 'lib/tapioca/gemfile.rb', line 154

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

#filesObject (readonly)

Returns the value of attribute files.



151
152
153
# File 'lib/tapioca/gemfile.rb', line 151

def files
  @files
end

#full_gem_pathObject (readonly)

Returns the value of attribute full_gem_path.



148
149
150
# File 'lib/tapioca/gemfile.rb', line 148

def full_gem_path
  @full_gem_path
end

#versionObject (readonly)

Returns the value of attribute version.



148
149
150
# File 'lib/tapioca/gemfile.rb', line 148

def version
  @version
end

Instance Method Details

#contains_path?(path) ⇒ Boolean



179
180
181
182
183
184
185
# File 'lib/tapioca/gemfile.rb', line 179

def contains_path?(path)
  if default_gem?
    files.any? { |file| file.to_s == to_realpath(path) }
  else
    to_realpath(path).start_with?(full_gem_path) || has_parent_gemspec?(path)
  end
end

#export_rbi_files?Boolean



198
199
200
# File 'lib/tapioca/gemfile.rb', line 198

def export_rbi_files?
  exported_rbi_files.any?
end

#exported_rbi_filesObject



193
194
195
# File 'lib/tapioca/gemfile.rb', line 193

def exported_rbi_files
  @exported_rbi_files ||= Dir.glob("#{full_gem_path}/rbi/**/*.rbi").sort
end

#exported_rbi_treeObject



203
204
205
206
207
208
209
210
211
212
# File 'lib/tapioca/gemfile.rb', line 203

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



164
165
166
# File 'lib/tapioca/gemfile.rb', line 164

def ignore?(gemfile_dir)
  gem_ignored? || gem_in_app_dir?(gemfile_dir, full_gem_path)
end

#nameObject



169
170
171
# File 'lib/tapioca/gemfile.rb', line 169

def name
  @spec.name
end

#parse_yard_docsObject



188
189
190
# File 'lib/tapioca/gemfile.rb', line 188

def parse_yard_docs
  files.each { |path| YARD.parse(path.to_s, [], Logger::Severity::FATAL) }
end

#rbi_file_nameObject



174
175
176
# File 'lib/tapioca/gemfile.rb', line 174

def rbi_file_name
  "#{name}@#{version}.rbi"
end