Class: ArchSpec::Rules::CannotDefineMethodRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::CannotDefineMethodRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Overview
Backs ArchSpec::DSL::ComponentProxy#cannot_define. Flags method definitions in the component matching the named methods.
Instance Attribute Summary collapse
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source, methods) ⇒ CannotDefineMethodRule
constructor
A new instance of CannotDefineMethodRule.
- #merge!(other) ⇒ Object
- #merge_key ⇒ Object
Constructor Details
#initialize(source, methods) ⇒ CannotDefineMethodRule
Returns a new instance of CannotDefineMethodRule.
173 174 175 176 |
# File 'lib/archspec/rules/protocol_rules.rb', line 173 def initialize(source, methods) @source = source.to_sym @method_names = Array(methods).flatten.map(&:to_sym) end |
Instance Attribute Details
#method_names ⇒ Object (readonly)
Returns the value of attribute method_names.
171 172 173 |
# File 'lib/archspec/rules/protocol_rules.rb', line 171 def method_names @method_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
171 172 173 |
# File 'lib/archspec/rules/protocol_rules.rb', line 171 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/archspec/rules/protocol_rules.rb', line 191 def evaluate(graph) graph.method_definitions_for_component(source).filter_map do |method_definition| next unless method_names.include?(method_definition.name) Diagnostic.new( rule: id, message: "#{source} must not define ##{method_definition.name}", location: method_definition.location, evidence: "#{method_definition.owner} defines #{method_definition.scope} method #{method_definition.name}" ) end end |
#id ⇒ Object
187 188 189 |
# File 'lib/archspec/rules/protocol_rules.rb', line 187 def id 'methods.define_forbid' end |
#merge!(other) ⇒ Object
182 183 184 185 |
# File 'lib/archspec/rules/protocol_rules.rb', line 182 def merge!(other) @method_names |= other.method_names self end |
#merge_key ⇒ Object
178 179 180 |
# File 'lib/archspec/rules/protocol_rules.rb', line 178 def merge_key [self.class, source] end |