Class: McpDiff::Core::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_diff/core/rule.rb

Overview

A single classification rule. The match block is instance_exec'd on the rule so it can call finding(...) and read id/severity — mirroring the TS this.id / this.class shape. Returns a Finding hash, an array of them, or nil. Findings use string keys to match the --json output shape.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, severity:, description:, &match) ⇒ Rule

Returns a new instance of Rule.



12
13
14
15
16
17
# File 'lib/mcp_diff/core/rule.rb', line 12

def initialize(id:, severity:, description:, &match)
  @id = id
  @severity = severity
  @description = description
  @match = match
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/mcp_diff/core/rule.rb', line 10

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/mcp_diff/core/rule.rb', line 10

def id
  @id
end

#severityObject (readonly)

Returns the value of attribute severity.



10
11
12
# File 'lib/mcp_diff/core/rule.rb', line 10

def severity
  @severity
end

Instance Method Details

#finding(target, message) ⇒ Object



23
24
25
# File 'lib/mcp_diff/core/rule.rb', line 23

def finding(target, message)
  { "ruleId" => @id, "class" => @severity, "target" => target, "message" => message }
end

#match(change) ⇒ Object



19
20
21
# File 'lib/mcp_diff/core/rule.rb', line 19

def match(change)
  instance_exec(change, &@match)
end