module ClientSideValidations::ActiveModel::Length

Public Instance Methods

client_side_hash(model, attribute, _force = nil) click to toggle source
# File lib/client_side_validations/active_model/length.rb, line 6
def client_side_hash(model, attribute, _force = nil)
  options = self.options.dup
  hash    = options_hash(options)

  self.class::MESSAGES.each do |option, message_type|
    count = options[option]
    next unless count

    options[:message] = options[message_type] if options[message_type].present?
    options.delete(:message) if options[:message].nil?
    hash[:messages][option] = model.errors.generate_message(attribute, message_type, options.merge(count: count))
    hash[option] = count
  end

  copy_conditional_attributes(hash, options)

  hash
end

Private Instance Methods

options_hash(options) click to toggle source
# File lib/client_side_validations/active_model/length.rb, line 27
def options_hash(options)
  hash = { messages: {} }
  hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
  hash
end