module ClientSideValidations::ActiveModel::Validator

Public Instance Methods

client_side_hash(model, attribute, _force = nil) click to toggle source
# File lib/client_side_validations/active_model.rb, line 10
def client_side_hash(model, attribute, _force = nil)
  build_client_side_hash(model, attribute, options.dup)
end
copy_conditional_attributes(attribute_to, attribute_from) click to toggle source
# File lib/client_side_validations/active_model.rb, line 14
def copy_conditional_attributes(attribute_to, attribute_from)
  %i[if unless].each { |key| attribute_to[key] = attribute_from[key] if attribute_from[key].present? }
end

Private Instance Methods

build_client_side_hash(model, attribute, options) click to toggle source
# File lib/client_side_validations/active_model.rb, line 20
def build_client_side_hash(model, attribute, options)
  # Rails mutates `options` object when calling `model.errors.generate_message`
  # by removing `message` option, if any.
  # By raising on missing translations, CSV has the same behavior across
  # all supported Rails versions and `config.i18n.raise_on_missing_translations`
  # possible configurations.
  options[:raise] = true

  message =
    begin
      model.errors.generate_message(attribute, message_type, options)
    rescue I18n::MissingTranslationData
      options[:message] = :invalid
      model.errors.generate_message(attribute, message_type, options)
    end

  options.delete(:raise)

  { message: message }.merge(options.except(*callbacks_options - %i[allow_blank if unless]))
end
callbacks_options() click to toggle source
# File lib/client_side_validations/active_model.rb, line 45
def callbacks_options
  ::ActiveModel::Error::CALLBACKS_OPTIONS
end
message_type() click to toggle source
# File lib/client_side_validations/active_model.rb, line 41
def message_type
  kind
end