File: length.rb

package info (click to toggle)
ruby-client-side-validations 3.2.6%2Bgh-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 676 kB
  • sloc: javascript: 3,019; ruby: 2,959; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module ClientSideValidations::ActiveModel
  module Length

    def client_side_hash(model, attribute, force = nil)
      options = self.options.dup
      hash    = { :messages => {} }
      hash[:js_tokenizer] = options[:js_tokenizer] if options[:js_tokenizer]
      hash[:allow_blank]  = true if options[:allow_blank]

      self.class::MESSAGES.each do |option, message_type|
        if count = options[option]
          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
      end

      copy_conditional_attributes(hash, options)

      hash
    end

  end
end