Class: Permittable::FinalizeRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/permittable.rb

Overview

The self a finalize block runs on. Deliberately bare — no controller delegation — so a contract cannot grow request-state dependencies; its whole vocabulary is the hash it receives plus violate!.

Instance Method Summary collapse

Constructor Details

#initialize(violations) ⇒ FinalizeRunner

Returns a new instance of FinalizeRunner.



533
534
535
# File 'lib/permittable.rb', line 533

def initialize(violations)
  @violations = violations
end

Instance Method Details

#violate!(param, code, message: nil) ⇒ Object

Records ONE violation and halts the finalize block immediately (the code after a violate! call never runs, so it can assume the checked invariant). The contract then fails as a normal 422. An optional message: rides along into the violation detail, same as a field's message: option.



542
543
544
545
546
547
# File 'lib/permittable.rb', line 542

def violate!(param, code, message: nil)
  entry = { param: param.to_s, code: code.to_s }
  entry[:message] = message.to_s if message
  @violations << entry
  throw :permittable_finalize_halt
end