Skip to content

Conversation

@bigforcegun
Copy link

@bigforcegun bigforcegun commented Nov 9, 2020

Try to close this one - #100
Starts with #101

Changes

  • add error_message param to validate methods
    • as it was in the documentation - supports String and Proc types
  • rewrite current error messaging mechanism to method build_error_message
    • can be nil context - when we validate without key pattern
    • can be context with setting_key: setting_key, setting_value: setting_value when we validate with key pattern
  • every current Validators have own default_error_message

Interface:

validate :enabled, :boolean, strict: true, error_message: 'You must use boolean types'
validate :count, :integer, strict: true, error_message: proc { |context|
                                                                  "Error with some key #{context[:setting_key]}"
                                                                }
 validate 'telegraf_url', error_message: message_proc do |value|
          value.is_a?(String)
        end

validate error_message: 'Error Message - global block' do
    settings.namespace.enabled.is_a?(Symbol)
end

validate by: :check_all, error_message: 'Error message - method call'

@DmitryDD
Copy link

hey @0exp could you please take a quick look at this PR?

@0exp
Copy link
Owner

0exp commented Jun 28, 2021

yes :O

@DmitryDD
Copy link

:zhdun:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants