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.



503
504
505
# File 'lib/permittable.rb', line 503

def initialize(violations)
  @violations = violations
end

Instance Method Details

#violate!(param, code) ⇒ 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.



510
511
512
513
# File 'lib/permittable.rb', line 510

def violate!(param, code)
  @violations << { param: param.to_s, code: code.to_s }
  throw :permittable_finalize_halt
end