Class: ArchSpec::Rules::Naming::Requires
- Inherits:
-
Object
- Object
- ArchSpec::Rules::Naming::Requires
- Defined in:
- lib/archspec/rules/naming_rules.rb
Overview
Requires each selected method to have a sibling named by a template, in
the same component or another (+on:+), at a given scope. The template
interpolates the selector's named captures, as in
requires("without_%{base}"). Rule id naming.requires.
Instance Method Summary collapse
- #diagnostics(selected, rule, graph) ⇒ Object
- #id ⇒ Object
-
#initialize(template, on: nil, scope: :instance, because: nil) ⇒ Requires
constructor
A new instance of Requires.
Constructor Details
#initialize(template, on: nil, scope: :instance, because: nil) ⇒ Requires
Returns a new instance of Requires.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/archspec/rules/naming_rules.rb', line 109 def initialize(template, on: nil, scope: :instance, because: nil) unless NamingRule::VALID_SCOPES.include?(scope) raise Error, "requires scope: must be :instance or :class, got #{scope.inspect}" end raise Error, "requires expects a String template, got #{template.inspect}" unless template.is_a?(String) @template = template @on = on @target_scope = scope @because = because end |
Instance Method Details
#diagnostics(selected, rule, graph) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/archspec/rules/naming_rules.rb', line 125 def diagnostics(selected, rule, graph) target = @on || rule.source existing = existing_names(graph, target) selected.filter_map do |definition, match| sibling = (match) next if sibling.nil? || existing.include?(sibling.to_sym) Diagnostic.new( rule: id, message: (definition, sibling, target, rule), location: definition.location, evidence: "#{definition.owner} defines ##{definition.name}, expected ##{sibling}" ) end end |
#id ⇒ Object
121 122 123 |
# File 'lib/archspec/rules/naming_rules.rb', line 121 def id 'naming.requires' end |