class Mudguard::Domain::Dependencies

Executes operation on a set of dependencies

Public Class Methods

new(policies:, notification:) click to toggle source
# File lib/mudguard/domain/dependencies.rb, line 11
def initialize(policies:, notification:)
  @policies = policies.map { |p| /^#{p}/x }
  @notification = notification
end

Public Instance Methods

check(dependencies) click to toggle source
# File lib/mudguard/domain/dependencies.rb, line 16
def check(dependencies)
  select_dependencies(dependencies) do |dependency, is_allowed|
    add_message(dependency, dependency_not_allowed(dependency.dependency)) unless is_allowed
    !is_allowed
  end
end
print_allowed(dependencies) click to toggle source

Private Instance Methods

add_message(dependency, message) click to toggle source
# File lib/mudguard/domain/dependencies.rb, line 32
def add_message(dependency, message)
  @notification.add(dependency.location, message)
end
dependency_allowed?(dependency) click to toggle source
# File lib/mudguard/domain/dependencies.rb, line 42
def dependency_allowed?(dependency)
  @policies.any? { |p| dependency.match(p) }
end
select_dependencies(dependencies) { |dependency, dependency_allowed?(dependency)| ... } click to toggle source
# File lib/mudguard/domain/dependencies.rb, line 36
def select_dependencies(dependencies)
  dependencies.select do |dependency|
    yield dependency, dependency_allowed?(dependency)
  end.count
end