Class: ClientSideValidations::ORM::ValidateOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/client_side_validations/orm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ ValidateOptions

Returns a new instance of ValidateOptions.



16
17
18
# File 'lib/client_side_validations/orm.rb', line 16

def initialize(base)
  self.base = base
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



14
15
16
# File 'lib/client_side_validations/orm.rb', line 14

def base
  @base
end

Instance Method Details

#to_hashObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/client_side_validations/orm.rb', line 20

def to_hash
  rules    = Hash.new { |h, field| h[field] = {} }
  messages = Hash.new { |h, field| h[field] = {} }
  base.validation_fields.each do |field|
    validations = validations_for(field)
    rules[field.to_s].merge!(extract_rules(validations, field))
    messages[field.to_s].merge!(extract_messages(validations))
  end
  {"rules" => rules, "messages" => messages}
end

#validations_for(field) ⇒ Object



31
32
33
# File 'lib/client_side_validations/orm.rb', line 31

def validations_for(field)
  adapter.validations_to_hash(field)
end