Class: QB::Package::Gem
- Inherits:
-
QB::Package
- Object
- Util::Resource
- QB::Package
- QB::Package::Gem
- Defined in:
- lib/qb/package/gem.rb
Overview
Package resource for a Ruby Gem.
Instance Attribute Summary
Attributes inherited from QB::Package
#name, #ref_path, #repo_rel_path, #root_path, #version
Class Method Summary collapse
- .from_root_path(path, repo: NRSER::NO_ARG) ⇒ QB::Package::Gem?
-
.from_root_path!(path) ⇒ QB::Package::Gem
Like Gem.from_root_path but raises an error if the path is not a gem root directory.
-
.gemspec_path(root_path) ⇒ Object
Find the only
*.gemspec
path in theroot_path
Gem directory.
Methods inherited from QB::Package
#in_repo?, #initialize, #repo, #version_tag, #version_tag_prefix, #versions
Methods inherited from Util::Resource
Constructor Details
This class inherits a constructor from QB::Package
Class Method Details
.from_root_path(path, repo: NRSER::NO_ARG) ⇒ QB::Package::Gem?
TODO:
Document from_path method.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/qb/package/gem.rb', line 74 def from_root_path path, repo: NRSER::NO_ARG # Values we will use to construct the resource instance. values = {repo: repo} # Whatever we were passes is the reference path values[:ref_path] = path # Cast to {Pathname} if it's not already and expand it to create the # root path values[:root_path] = path.to_pn. # Check that we're working with a directory, returning `nil` if we're not return nil unless values[:root_path].directory? # Get the path to the (single) Gemspec file. values[:gemspec_path] = self.gemspec_path values[:root_path] # Check that we got it, returning `nil` if we don't return nil if values[:gemspec_path].nil? # Load up the gemspec ad version values[:spec] = ::Gem::Specification::load values[:gemspec_path].to_s # Get the name from the spec values[:name] = values[:spec].name # Get the version from the spec values[:version] = QB::Package::Version.from values[:spec].version # Construct the resource instance and return it. new **values end |
.from_root_path!(path) ⇒ QB::Package::Gem
Like from_root_path but raises an error if the path is not a gem root directory.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/qb/package/gem.rb', line 120 def from_root_path! path from_root_path( path ).tap { |gem| if gem.nil? raise QB::FSStateError.squished <<-END Path #{ path.inspect } does not appear to be the root directory of a Ruby gem. END end } end |
.gemspec_path(root_path) ⇒ Object
Find the only *.gemspec
path in the root_path
Gem directory.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/qb/package/gem.rb', line 46 def gemspec_path root_path paths = Pathname.glob( root_path.to_pn / '*.gemspec' ) case paths.length when 0 nil when 1 paths[0] else nil end end |