class QB::Package

Common properties and methods of package resources, aimed at packages represented as directories in projects.

Public Class Methods

new(repo: NRSER::NO_ARG, **props) click to toggle source

Constructor

Calls superclass method QB::Util::Resource::new
# File lib/qb/package.rb, line 98
def initialize repo: NRSER::NO_ARG, **props
  @repo = repo
  super **props
end

Public Instance Methods

in_repo?() click to toggle source

@return [Boolean]

`true` if {#root_path} is in a repo type we recognize.
# File lib/qb/package.rb, line 130
def in_repo?
  !!repo
end
repo() click to toggle source

@todo Document repo method.

@param [type] arg_name

@todo Add name param description.

@return [return_type]

@todo Document return value.
# File lib/qb/package.rb, line 118
def repo
  if @repo == NRSER::NO_ARG
    @repo = QB::Repo.from_path root_path
  end
  
  @repo
end
repo_rel_path() click to toggle source

Relative path from the {#repo} root to the {#root_path}.

Used as the version tag prefix (unless it's `.` - when the repo root is the root path).

@return [Pathname]

# File lib/qb/package.rb, line 142
def repo_rel_path
  root_path.relative_path_from( repo.root_path ) if in_repo?
end
version_tag() click to toggle source

@return [String]

# File lib/qb/package.rb, line 198
def version_tag
  version_tag_prefix + version.semver
end
version_tag_prefix() click to toggle source

Get the string prefix for tagging versions of this package.

Only makes any sense if the package is in a recognized repo, and will error out if that's not the case.

The most basic prefix is “v” for packages located at the root of the repository.

@example

repo_root = '.'
package_root = repo_root
QB::Package.from_path( package_root ).version_tag_prefix
# => 'v'
# (an actual tag would look like 'v0.1.2')

To support “multi-package” repos - which is a way of dealing with apps that are composed of multiple versioned services without having to create a new submodule for every micro-service - packages that do not share the same root of the repo are prefixed by the relative path from the repo root to the package root.

@example

repo_root = Pathname.new '.'
package_root = repo_root / 'services' / 'some-service'
QB::Package.from_path( package_root ).version_tag_prefix
# => 'services/some-service/v'
# (an actual tag would look like 'services/some-service/v0.1.2')

This creates a unique and intuitive namespace scheme for supporting multiple independent package versions in a single repo, which has proved handy for container-ized apps.

Unless, of course, you change the package's path. Then it will get wonky. We'll burn that bridge when we come to it.

@return [String]

# File lib/qb/package.rb, line 184
def version_tag_prefix
  if root_path == repo.root_path
    'v'
  else
    (repo_rel_path / 'v').to_s
  end
end
versions() click to toggle source

@todo Document versions method.

@param [type] arg_name

@todo Add name param description.

@return [return_type]

@todo Document return value.
# File lib/qb/package.rb, line 211
def versions
  # method body...
end