Class: Packwerk::Package
- Inherits:
-
Object
- Object
- Packwerk::Package
- Extended by:
- T::Sig
- Includes:
- Comparable
- Defined in:
- lib/packwerk/package.rb
Overview
The basic unit of modularity for packwerk; a folder that has been declared to define a package. The package contains all constants defined in files in this folder and all subfolders that are not packages themselves.
Constant Summary collapse
- ROOT_PACKAGE_NAME =
"."
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #dependency?(package) ⇒ Boolean
- #enforce_dependencies? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, config: nil) ⇒ Package
constructor
A new instance of Package.
- #package_path?(path) ⇒ Boolean
- #root? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name:, config: nil) ⇒ Package
Returns a new instance of Package.
24 25 26 27 28 29 |
# File 'lib/packwerk/package.rb', line 24 def initialize(name:, config: nil) @name = name @config = T.let(config || {}, T::Hash[String, T.untyped]) @dependencies = T.let(Array(@config["dependencies"]).freeze, T::Array[String]) @public_path = T.let(nil, T.nilable(String)) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/packwerk/package.rb', line 21 def config @config end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
18 19 20 |
# File 'lib/packwerk/package.rb', line 18 def dependencies @dependencies end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/packwerk/package.rb', line 15 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
49 50 51 52 53 |
# File 'lib/packwerk/package.rb', line 49 def <=>(other) return nil unless other.is_a?(self.class) name <=> other.name end |
#dependency?(package) ⇒ Boolean
37 38 39 |
# File 'lib/packwerk/package.rb', line 37 def dependency?(package) @dependencies.include?(package.name) end |
#enforce_dependencies? ⇒ Boolean
32 33 34 |
# File 'lib/packwerk/package.rb', line 32 def enforce_dependencies? [true, "strict"].include?(@config["enforce_dependencies"]) end |
#eql?(other) ⇒ Boolean
56 57 58 |
# File 'lib/packwerk/package.rb', line 56 def eql?(other) self == other end |
#hash ⇒ Object
61 62 63 |
# File 'lib/packwerk/package.rb', line 61 def hash name.hash end |
#package_path?(path) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/packwerk/package.rb', line 42 def package_path?(path) return true if root? path.start_with?(@name + "/") end |
#root? ⇒ Boolean
71 72 73 |
# File 'lib/packwerk/package.rb', line 71 def root? @name == ROOT_PACKAGE_NAME end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/packwerk/package.rb', line 66 def to_s name end |