Class: Tapioca::Gemfile::GemSpec

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/gemfile.rb

Constant Summary collapse

IGNORED_GEMS =
T.let(["sorbet", "sorbet-static", "sorbet-runtime"].freeze, T::Array[String])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ GemSpec

Returns a new instance of GemSpec.



103
104
105
106
107
108
109
# File 'lib/tapioca/gemfile.rb', line 103

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]))
end

Instance Attribute Details

#full_gem_pathObject (readonly)

Returns the value of attribute full_gem_path.



100
101
102
# File 'lib/tapioca/gemfile.rb', line 100

def full_gem_path
  @full_gem_path
end

#versionObject (readonly)

Returns the value of attribute version.



100
101
102
# File 'lib/tapioca/gemfile.rb', line 100

def version
  @version
end

Instance Method Details

#contains_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


142
143
144
145
146
147
148
# File 'lib/tapioca/gemfile.rb', line 142

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

Returns:

  • (Boolean)


161
162
163
# File 'lib/tapioca/gemfile.rb', line 161

def export_rbi_files?
  exported_rbi_files.any?
end

#exported_rbi_filesObject



156
157
158
# File 'lib/tapioca/gemfile.rb', line 156

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

#exported_rbi_treeObject



166
167
168
169
170
171
172
173
174
175
# File 'lib/tapioca/gemfile.rb', line 166

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

#filesObject



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/tapioca/gemfile.rb', line 117

def files
  if default_gem?
    # `Bundler::RemoteSpecification` delegates missing methods to
    # `Gem::Specification`, so `files` actually always exists on spec.
    T.unsafe(@spec).files.map do |file|
      ruby_lib_dir.join(file)
    end
  else
    @spec.full_require_paths.flat_map do |path|
      Pathname.glob((Pathname.new(path) / "**/*.rb").to_s)
    end
  end
end

#ignore?(gemfile_dir) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/tapioca/gemfile.rb', line 112

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

#nameObject



132
133
134
# File 'lib/tapioca/gemfile.rb', line 132

def name
  @spec.name
end

#parse_yard_docsObject



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

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

#rbi_file_nameObject



137
138
139
# File 'lib/tapioca/gemfile.rb', line 137

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