Module: Campo::Plugins::JQueryValidation::Rules

Defined in:
lib/campo/plugins/jqueryvalidation.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



39
40
41
# File 'lib/campo/plugins/jqueryvalidation.rb', line 39

def self.[](key)
  Rules.rules[key]
end

.[]=(key, value) ⇒ Object



42
43
44
45
46
# File 'lib/campo/plugins/jqueryvalidation.rb', line 42

def self.[]=( key,value )
  value = {value => true} unless value.kind_of? Hash
  Rules.rules[key].merge! value
  Rules.rules
end

.renderObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/campo/plugins/jqueryvalidation.rb', line 16

def self.render
  return "" if Rules.rules.empty?
  output = @jqv_rules.map do |(field,rs)| 
    "#{field}: { " << 
    rs.map{|k,v| "#{k}: #{v}" }.join(", ") <<
    " }"
  end.join(",\n" + "  " * 4)
  output = <<STR
rules: {
#{output}
      }
STR
   
  output.chomp
end

.resetObject



47
48
49
# File 'lib/campo/plugins/jqueryvalidation.rb', line 47

def self.reset
  @jqv_rules = nil
end

.rulesObject



31
32
33
34
35
36
37
# File 'lib/campo/plugins/jqueryvalidation.rb', line 31

def self.rules
  if @jqv_rules.nil?
      @jqv_rules = {}
      @jqv_rules.default_proc = proc {|hash, key| hash[key] = {} }
    end
  @jqv_rules
end