Class: Devpack::GemSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/devpack/gem_spec.rb

Overview

Locates relevant gemspec for a given gem and provides a full list of paths for all ‘require_paths` listed in gemspec. rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(glob, name, requirement, root: nil) ⇒ GemSpec

Returns a new instance of GemSpec.



10
11
12
13
14
15
16
# File 'lib/devpack/gem_spec.rb', line 10

def initialize(glob, name, requirement, root: nil)
  @name = name
  @glob = glob
  @requirement = requirement
  @root = root || self
  @dependency = Gem::Dependency.new(@name, @requirement)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/devpack/gem_spec.rb', line 8

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/devpack/gem_spec.rb', line 8

def root
  @root
end

Instance Method Details

#gemspecObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/devpack/gem_spec.rb', line 24

def gemspec
  return Gem.loaded_specs[@name] if compatible?(Gem.loaded_specs[@name])

  @gemspec ||= gemspecs.find do |spec|
    next false if spec.nil?

    raise_incompatible(spec) unless compatible?(spec)

    @dependency.requirement.satisfied_by?(spec.version)
  end
end

#pretty_nameObject



36
37
38
39
40
# File 'lib/devpack/gem_spec.rb', line 36

def pretty_name
  return @name.to_s if @requirement.nil?

  "#{@name} #{@requirement}"
end

#require_paths(visited = Set.new) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/devpack/gem_spec.rb', line 18

def require_paths(visited = Set.new)
  raise GemNotFoundError.new("Gem not found: #{required_version}", self) if gemspec.nil?

  (immediate_require_paths + dependency_require_paths(visited)).compact.flatten.uniq
end

#required_versionObject



46
47
48
49
50
51
# File 'lib/devpack/gem_spec.rb', line 46

def required_version
  return @name.to_s if compatible_spec.nil? && @requirement.nil?
  return "#{@name}:#{compatible_version}" if compatible_spec.nil?

  "#{@name}:#{compatible_spec.version}"
end

#root?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/devpack/gem_spec.rb', line 42

def root?
  self == @root
end