You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We sometimes use AI to manually perform certain custom actions. This exposes us to human errors in the naming of optional arguments. Is it possible to have AI fail if arguments are passed for which no filter has been defined?
I think that might be useful to have, in the meantime it's possible with a simple module
moduleEnforceFiltersextendActiveSupport::ConcernMissingFilterError=Class.new(StandardError)includeddoclass_attribute:enforce_filtersenddefpopulate_reader(key,value)ifenforce_filters && !respond_to?(key)raiseMissingFilterError,"no filter defined for argument `#{key}`"endsuperendclass_methodsdodefenforce_filters!self.enforce_filters=trueendendendclassObjectInteraction < ActiveInteraction::BaseincludeEnforceFiltersboolean:commit,default: trueenforce_filters!defexecutecommitendendObjectInteraction.run!(comit: false)# => no filter defined for argument `comit` (EnforceFilters::MissingFilterError)
I rewrote the example from @antulik so it works for 4.0.5
moduleEnforceFiltersextendActiveSupport::ConcernMissingFilterError=Class.new(StandardError)includeddoclass_attribute:enforce_filtersenddefpopulate_filters_and_inputs(inputs)validate_arguments(inputs.keys)ifenforce_filterssuperenddefvalidate_arguments(arguments)arguments.eachdo |argument|
raiseMissingFilterError,"no filter defined for argument `#{argument}`"unlessrespond_to?(argument)endendclass_methodsdodefenforce_filters!self.enforce_filters=trueendendendclassObjectInteraction < ActiveInteraction::BaseincludeEnforceFiltersboolean:commit,default: trueenforce_filters!defexecutecommitendendObjectInteraction.run!(comit: false)# => no filter defined for argument `comit` (EnforceFilters::MissingFilterError)
We sometimes use AI to manually perform certain custom actions. This exposes us to human errors in the naming of optional arguments. Is it possible to have AI fail if arguments are passed for which no filter has been defined?
Example
This command will unintentionally commit the transaction since the argument is misspelled.
Solution?
Introduce a class method and/or global option that changes the default behavior.
The text was updated successfully, but these errors were encountered: