Class: LayerChecker::Module
- Inherits:
-
Object
- Object
- LayerChecker::Module
- Defined in:
- lib/layer_checker/module.rb
Instance Attribute Summary collapse
-
#depends_on ⇒ Object
readonly
Returns the value of attribute depends_on.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#submodules ⇒ Object
readonly
Returns the value of attribute submodules.
Instance Method Summary collapse
-
#all_modules ⇒ Object
Get all modules (including nested ones) as a flat hash.
-
#allowed_dependencies ⇒ Object
Get all allowed dependencies (resolving relative names).
-
#can_depend_on?(other_module_name) ⇒ Boolean
Check if this module can depend on another module.
-
#full_name ⇒ Object
Get the full qualified name (e.g., “billing.domain”).
-
#initialize(name, config = {}, parent: nil) ⇒ Module
constructor
A new instance of Module.
-
#matches_file?(file_path) ⇒ Boolean
Check if a file path belongs to this module.
- #to_s ⇒ Object
Constructor Details
#initialize(name, config = {}, parent: nil) ⇒ Module
Returns a new instance of Module.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/layer_checker/module.rb', line 7 def initialize(name, config = {}, parent: nil) @name = name @parent = parent @paths = Array(config['paths'] || []) @depends_on = Array(config['depends_on'] || []) @submodules = {} # Parse nested modules if they exist if config['modules'] config['modules'].each do |submodule_name, submodule_config| @submodules[submodule_name] = Module.new(submodule_name, submodule_config, parent: self) end end end |
Instance Attribute Details
#depends_on ⇒ Object (readonly)
Returns the value of attribute depends_on.
5 6 7 |
# File 'lib/layer_checker/module.rb', line 5 def depends_on @depends_on end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/layer_checker/module.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/layer_checker/module.rb', line 5 def parent @parent end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
5 6 7 |
# File 'lib/layer_checker/module.rb', line 5 def paths @paths end |
#submodules ⇒ Object (readonly)
Returns the value of attribute submodules.
5 6 7 |
# File 'lib/layer_checker/module.rb', line 5 def submodules @submodules end |
Instance Method Details
#all_modules ⇒ Object
Get all modules (including nested ones) as a flat hash
33 34 35 36 37 38 39 |
# File 'lib/layer_checker/module.rb', line 33 def all_modules result = { full_name => self } @submodules.each_value do |submodule| result.merge!(submodule.all_modules) end result end |
#allowed_dependencies ⇒ Object
Get all allowed dependencies (resolving relative names)
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/layer_checker/module.rb', line 56 def allowed_dependencies return @depends_on unless parent # For nested modules, resolve dependencies relative to parent @depends_on.map do |dep| # If it's a simple name, it refers to a sibling if parent.submodules.key?(dep) "#{parent.full_name}.#{dep}" else dep end end end |
#can_depend_on?(other_module_name) ⇒ Boolean
Check if this module can depend on another module
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/layer_checker/module.rb', line 42 def can_depend_on?(other_module_name) # Direct dependency check return true if @depends_on.include?(other_module_name) # Check if it's a sibling module (same parent) if parent sibling_names = parent.submodules.keys return @depends_on.any? { |dep| sibling_names.include?(dep) && dep == other_module_name } end false end |
#full_name ⇒ Object
Get the full qualified name (e.g., “billing.domain”)
28 29 30 |
# File 'lib/layer_checker/module.rb', line 28 def full_name parent ? "#{parent.full_name}.#{name}" : name end |
#matches_file?(file_path) ⇒ Boolean
Check if a file path belongs to this module
23 24 25 |
# File 'lib/layer_checker/module.rb', line 23 def matches_file?(file_path) @paths.any? { |pattern| File.fnmatch?(pattern, file_path, File::FNM_PATHNAME) } end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/layer_checker/module.rb', line 70 def to_s full_name end |