Class: ArchSpec::Rules::CannotDefineMethodRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::CannotDefineMethodRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
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.
124 125 126 127 |
# File 'lib/archspec/rules/protocol_rules.rb', line 124 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.
122 123 124 |
# File 'lib/archspec/rules/protocol_rules.rb', line 122 def method_names @method_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
122 123 124 |
# File 'lib/archspec/rules/protocol_rules.rb', line 122 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/archspec/rules/protocol_rules.rb', line 142 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
138 139 140 |
# File 'lib/archspec/rules/protocol_rules.rb', line 138 def id "methods.define_forbid" end |
#merge!(other) ⇒ Object
133 134 135 136 |
# File 'lib/archspec/rules/protocol_rules.rb', line 133 def merge!(other) @method_names |= other.method_names self end |
#merge_key ⇒ Object
129 130 131 |
# File 'lib/archspec/rules/protocol_rules.rb', line 129 def merge_key [self.class, source] end |