class ArchSpec::Rules::PublicApiRule
Backs ArchSpec::DSL::ComponentProxy#public_api. Flags references from outside the component to constants that are not part of its public API.
Attributes
Public Class Methods
# File lib/archspec/rules/privacy_rule.rb, line 10 def initialize(source, files: [], constants: nil, namespaces: nil) @source = source.to_sym @file_patterns = Array(files).flatten.compact.map(&:to_s) @constants = Array(constants).compact.map { |value| normalize_constant(value) } @namespaces = Array(namespaces).compact.map { |value| normalize_constant(value) } end
Public Instance Methods
Source
# File lib/archspec/rules/privacy_rule.rb, line 32 def evaluate(graph) component = graph.components[source] return [] unless component public_names = public_constant_names(graph) graph.dependency_edges.filter_map do |edge| next if component.files.include?(edge.from_path) resolved = graph.resolve_constant_reference(edge.to, edge.from_constant) next unless graph.component_names_for_constant(resolved).include?(source) next if public?(resolved, public_names) Diagnostic.new( rule: id, message: "#{resolved} is private to #{source}", location: edge.location, evidence: "#{edge.from_constant || edge.from_path} #{edge.type} #{resolved}" ) end end
Source
# File lib/archspec/rules/privacy_rule.rb, line 21 def merge!(other) @file_patterns |= other.file_patterns @constants |= other.constants @namespaces |= other.namespaces self end
Source
# File lib/archspec/rules/privacy_rule.rb, line 17 def merge_key [self.class, source] end