From 4c136c62b2cf90d48f9257d9c3ae9bd5a3040ca0 Mon Sep 17 00:00:00 2001 From: Anton Katunin Date: Sat, 29 Jun 2024 14:44:25 +1000 Subject: [PATCH] Add include_errors! --- lib/active_interaction/extras.rb | 8 ++++++++ lib/active_interaction/extras/all.rb | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/active_interaction/extras.rb b/lib/active_interaction/extras.rb index 68a9723..90356bf 100644 --- a/lib/active_interaction/extras.rb +++ b/lib/active_interaction/extras.rb @@ -75,6 +75,14 @@ def initialize_with(&block) end end + concern :IncludeErrors do + include ActiveInteraction::Extras::Halt + + def include_errors!(model, **mapping) + errors.merge! model.errors, **mapping + halt_if_errors! + end + end end end diff --git a/lib/active_interaction/extras/all.rb b/lib/active_interaction/extras/all.rb index da5ae22..bf67dfa 100644 --- a/lib/active_interaction/extras/all.rb +++ b/lib/active_interaction/extras/all.rb @@ -13,5 +13,6 @@ module ActiveInteraction::Extras::All include ActiveInteraction::Extras::FormFor include ActiveInteraction::Extras::AfterInitialize include ActiveInteraction::Extras::InitializeWith + include ActiveInteraction::Extras::IncludeErrors end