Module: ArchSpec::Rules::ProtocolEvidence
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Overview
Builds the shared "methods: ..." evidence string for the protocol rules and resolves the classes in a component. Internal helper.
Constant Summary collapse
- VALID_SCOPES =
%i[instance class].freeze
Class Method Summary collapse
- .constants_for(graph, source) ⇒ Object
- .for(constant, methods, unresolved, scope: :instance) ⇒ Object
- .validate_scope!(scope, for_rule:) ⇒ Object
Class Method Details
.constants_for(graph, source) ⇒ Object
250 251 252 253 254 255 |
# File 'lib/archspec/rules/protocol_rules.rb', line 250 def constants_for(graph, source) component = graph.components[source] return [] unless component graph.constants_for_component(source).select(&:class?).uniq(&:name) end |
.for(constant, methods, unresolved, scope: :instance) ⇒ Object
257 258 259 260 261 262 263 |
# File 'lib/archspec/rules/protocol_rules.rb', line 257 def for(constant, methods, unresolved, scope: :instance) label = scope == :class ? 'class methods' : 'methods' evidence = "#{constant.name} #{label}: #{methods.empty? ? '(none)' : methods.to_a.sort.join(', ')}" return evidence if unresolved.empty? "#{evidence}; unresolved ancestors: #{unresolved.to_a.sort.join(', ')}" end |
.validate_scope!(scope, for_rule:) ⇒ Object
244 245 246 247 248 |
# File 'lib/archspec/rules/protocol_rules.rb', line 244 def validate_scope!(scope, for_rule:) return if VALID_SCOPES.include?(scope) raise Error, "#{for_rule} scope: must be :instance or :class, got #{scope.inspect}" end |