Class: Insika::Parity::Criterion

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/parity/criterion.rb

Overview

C5 — the frozen criterion, parsed from the deployment's criterion file. The prose a human reads and the yaml block the machine applies are the SAME file, so there is exactly one place to edit — and the file's WHOLE bytes are hashed, so an edit to the rationale invalidates the frozen rule too, which is correct: the rationale is what makes the numbers reviewable.

Strict by construction: a missing key or an unknown key is refused at load (ValidationError), and no key has a default — a number the machine filled in is a number nobody pre-registered.

Defined Under Namespace

Classes: Rule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule:, path:, sha:) ⇒ Criterion

Returns a new instance of Criterion.



29
30
31
32
33
# File 'lib/insika/parity/criterion.rb', line 29

def initialize(rule:, path:, sha:)
  @rule = rule
  @path = path
  @sha = sha
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/insika/parity/criterion.rb', line 27

def path
  @path
end

#ruleObject (readonly)

Returns the value of attribute rule.



27
28
29
# File 'lib/insika/parity/criterion.rb', line 27

def rule
  @rule
end

#shaObject (readonly)

Returns the value of attribute sha.



27
28
29
# File 'lib/insika/parity/criterion.rb', line 27

def sha
  @sha
end

Class Method Details

.load(path) ⇒ Object

Reads the file, extracts the FIRST ```yaml fence, validates STRICTLY. Raises Insika::ConfigError when the file is absent or has no block; Insika::ValidationError on an unknown or missing key.



38
39
40
41
42
43
44
# File 'lib/insika/parity/criterion.rb', line 38

def self.load(path)
  bytes = read_bytes(path)
  block = extract_yaml_block(bytes)
  parsed = YAML.safe_load(block, permitted_classes: [], aliases: false)
  rule = build_rule(parsed)
  new(rule: rule, path: path, sha: "sha256:#{Digest::SHA256.hexdigest(bytes)}")
end

Instance Method Details

#to_hObject



46
# File 'lib/insika/parity/criterion.rb', line 46

def to_h = @rule.to_h