class Boxwerk::Package
Data class representing a package. Reads the standard package.yml format.
Attributes
Public Class Methods
Source
# File lib/boxwerk/package.rb, line 45 def self.from_yml(yml_path, root_path:) config = YAML.safe_load_file(yml_path) || {} pkg_dir = File.dirname(yml_path) name = if File.expand_path(pkg_dir) == File.expand_path(root_path) '.' else relative_path(pkg_dir, root_path) end # Normalize dependency names declared in the package.yml if config['dependencies'] config = config.dup config['dependencies'] = config['dependencies'].map { |d| normalize(d) } end new(name: name, config: config) end
Loads a Package from a package.yml file. The name is the relative path from root_path to the package directory.
Source
# File lib/boxwerk/package.rb, line 66 def self.implicit_root(all_package_names) new( name: '.', config: { 'enforce_dependencies' => false, 'enforce_privacy' => false, 'dependencies' => all_package_names.reject { |n| n == '.' }, }, ) end
Creates an implicit root package that depends on all other packages. No enforcement is enabled.
Source
# File lib/boxwerk/package.rb, line 8 def initialize(name:, config: {}) @name = name @config = config end
Source
# File lib/boxwerk/package.rb, line 80 def self.normalize(name) name = name.to_s.strip name = name.sub(%r{\A\./}, '') name = name.sub(%r{/\z}, '') name end
Normalizes a package name: strips leading ./ and trailing /. Allows users to write packs/loyalty/, ./packs/loyalty, or packs/loyalty interchangeably in package.yml dependencies and CLI –package flag.
Source
# File lib/boxwerk/package.rb, line 87 def self.relative_path(path, base) Pathname .new(File.expand_path(path)) .relative_path_from(Pathname.new(File.expand_path(base))) .to_s end
Public Instance Methods
Source
# File lib/boxwerk/package.rb, line 25 def ==(other) other.is_a?(Package) && name == other.name end
Also aliased as: eql?
Source
# File lib/boxwerk/package.rb, line 17 def dependencies @config['dependencies'] || [] end
Source
# File lib/boxwerk/package.rb, line 21 def enforce_dependencies? @config['enforce_dependencies'] == true end
Source
# File lib/boxwerk/package.rb, line 39 def inspect "#<Boxwerk::Package #{name}>" end