Class: Tapioca::Gemfile::GemSpec
- Inherits:
-
Object
- Object
- Tapioca::Gemfile::GemSpec
- Extended by:
- T::Sig
- Includes:
- Tapioca::GemHelper
- Defined in:
- lib/tapioca/gemfile.rb
Constant Summary collapse
- IGNORED_GEMS =
[ "sorbet", "sorbet-static", "sorbet-runtime", "sorbet-static-and-runtime", "debug", "irb", "fakefs", ].freeze
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
: Array.
-
#full_gem_path ⇒ Object
readonly
: String.
-
#version ⇒ Object
readonly
: String.
Class Method Summary collapse
-
.spec_lookup_by_file_path ⇒ Object
: -> Hash[String, Gemfile::GemSpec].
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (BasicObject other) -> bool.
-
#contains_path?(path) ⇒ Boolean
: (String path) -> bool.
-
#dependencies ⇒ Object
: -> Array.
-
#export_rbi_files? ⇒ Boolean
: -> bool.
-
#exported_rbi_files ⇒ Object
: -> Array.
-
#exported_rbi_tree ⇒ Object
: -> RBI::MergeTree.
-
#ignore?(gemfile_dir) ⇒ Boolean
: (String gemfile_dir) -> bool.
-
#initialize(spec) ⇒ GemSpec
constructor
: (Spec spec) -> void.
-
#name ⇒ Object
: -> String.
-
#rbi_file_name ⇒ Object
: -> String.
-
#relative_path_for(file) ⇒ Object
: (Pathname file) -> Pathname.
Methods included from Tapioca::GemHelper
#gem_in_app_dir?, #gem_in_bundle_path?, #gem_in_ruby_path?, #to_realpath
Constructor Details
#initialize(spec) ⇒ GemSpec
: (Spec spec) -> void
150 151 152 153 154 155 156 157 |
# File 'lib/tapioca/gemfile.rb', line 150 def initialize(spec) @spec = spec #: Tapioca::Gemfile::Spec real_gem_path = to_realpath(@spec.full_gem_path) @full_gem_path = real_gem_path #: String @version = version_string #: String @exported_rbi_files = nil #: Array[String]? @files = collect_files #: Array[Pathname] end |
Instance Attribute Details
#files ⇒ Object (readonly)
: Array
147 148 149 |
# File 'lib/tapioca/gemfile.rb', line 147 def files @files end |
#full_gem_path ⇒ Object (readonly)
: String
144 145 146 |
# File 'lib/tapioca/gemfile.rb', line 144 def full_gem_path @full_gem_path end |
#version ⇒ Object (readonly)
: String
144 145 146 |
# File 'lib/tapioca/gemfile.rb', line 144 def version @version end |
Class Method Details
.spec_lookup_by_file_path ⇒ Object
: -> Hash[String, Gemfile::GemSpec]
124 125 126 127 128 129 130 |
# File 'lib/tapioca/gemfile.rb', line 124 def spec_lookup_by_file_path @lookup ||= [*::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 #: Hash[String, Gemfile::GemSpec]? end |
Instance Method Details
#==(other) ⇒ Object
: (BasicObject other) -> bool
160 161 162 |
# File 'lib/tapioca/gemfile.rb', line 160 def ==(other) GemSpec === other && other.name == name && other.version == version end |
#contains_path?(path) ⇒ Boolean
: (String path) -> bool
185 186 187 188 189 190 191 |
# File 'lib/tapioca/gemfile.rb', line 185 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 |
#dependencies ⇒ Object
: -> Array
175 176 177 |
# File 'lib/tapioca/gemfile.rb', line 175 def dependencies @spec.dependencies end |
#export_rbi_files? ⇒ Boolean
: -> bool
199 200 201 |
# File 'lib/tapioca/gemfile.rb', line 199 def export_rbi_files? exported_rbi_files.any? end |
#exported_rbi_files ⇒ Object
: -> Array
194 195 196 |
# File 'lib/tapioca/gemfile.rb', line 194 def exported_rbi_files @exported_rbi_files ||= Dir.glob("#{full_gem_path}/rbi/**/*.rbi").sort end |
#exported_rbi_tree ⇒ Object
: -> RBI::MergeTree
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/tapioca/gemfile.rb', line 204 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
: (String gemfile_dir) -> bool
165 166 167 |
# File 'lib/tapioca/gemfile.rb', line 165 def ignore?(gemfile_dir) gem_ignored? || gem_in_app_dir?(gemfile_dir, full_gem_path) end |
#name ⇒ Object
: -> String
170 171 172 |
# File 'lib/tapioca/gemfile.rb', line 170 def name @spec.name end |
#rbi_file_name ⇒ Object
: -> String
180 181 182 |
# File 'lib/tapioca/gemfile.rb', line 180 def rbi_file_name "#{name}@#{version}.rbi" end |
#relative_path_for(file) ⇒ Object
: (Pathname file) -> Pathname
216 217 218 219 220 221 222 |
# File 'lib/tapioca/gemfile.rb', line 216 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 |