Class: Packwerk::Package
- Inherits:
-
Object
- Object
- Packwerk::Package
- 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
: Hash[untyped, untyped].
-
#dependencies ⇒ Object
readonly
: Array.
-
#name ⇒ Object
readonly
: String.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
: (untyped other) -> Integer?.
-
#dependency?(package) ⇒ Boolean
: (Package package) -> bool.
-
#enforce_dependencies? ⇒ Boolean
: -> bool.
-
#eql?(other) ⇒ Boolean
: (untyped other) -> bool.
-
#hash ⇒ Object
: -> Integer.
-
#initialize(name:, config: nil) ⇒ Package
constructor
: (name: String, ?config: Hash[String, untyped]?) -> void.
-
#package_path?(path) ⇒ Boolean
: (String path) -> bool.
-
#root? ⇒ Boolean
: -> bool.
-
#to_s ⇒ Object
: -> String.
Constructor Details
#initialize(name:, config: nil) ⇒ Package
: (name: String, ?config: Hash[String, untyped]?) -> void
23 24 25 26 27 28 |
# File 'lib/packwerk/package.rb', line 23 def initialize(name:, config: nil) @name = name @config = config || {} #: Hash[String, untyped] @dependencies = Array(@config["dependencies"]).freeze #: Array[String] @public_path = nil #: String? end |
Instance Attribute Details
#config ⇒ Object (readonly)
: Hash[untyped, untyped]
20 21 22 |
# File 'lib/packwerk/package.rb', line 20 def config @config end |
#dependencies ⇒ Object (readonly)
: Array
17 18 19 |
# File 'lib/packwerk/package.rb', line 17 def dependencies @dependencies end |
#name ⇒ Object (readonly)
: String
14 15 16 |
# File 'lib/packwerk/package.rb', line 14 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
: (untyped other) -> Integer?
48 49 50 51 52 |
# File 'lib/packwerk/package.rb', line 48 def <=>(other) return nil unless other.is_a?(self.class) name <=> other.name end |
#dependency?(package) ⇒ Boolean
: (Package package) -> bool
36 37 38 |
# File 'lib/packwerk/package.rb', line 36 def dependency?(package) @dependencies.include?(package.name) end |
#enforce_dependencies? ⇒ Boolean
: -> bool
31 32 33 |
# File 'lib/packwerk/package.rb', line 31 def enforce_dependencies? [true, "strict"].include?(@config["enforce_dependencies"]) end |
#eql?(other) ⇒ Boolean
: (untyped other) -> bool
55 56 57 |
# File 'lib/packwerk/package.rb', line 55 def eql?(other) self == other end |
#hash ⇒ Object
: -> Integer
60 61 62 |
# File 'lib/packwerk/package.rb', line 60 def hash name.hash end |
#package_path?(path) ⇒ Boolean
: (String path) -> bool
41 42 43 44 45 |
# File 'lib/packwerk/package.rb', line 41 def package_path?(path) return true if root? path.start_with?(@name + "/") end |
#root? ⇒ Boolean
: -> bool
70 71 72 |
# File 'lib/packwerk/package.rb', line 70 def root? @name == ROOT_PACKAGE_NAME end |
#to_s ⇒ Object
: -> String
65 66 67 |
# File 'lib/packwerk/package.rb', line 65 def to_s name end |