Class: Class

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sidesObject



25
26
27
# File 'lib/validation_profiler.rb', line 25

def self.sides
  @@sides
end

Instance Method Details

#validates(field, rule, attributes = {}) ⇒ Object

Specifies a validation rule to use within a validation profile.

Parameters:

  • field (Symbol)

    The name of the field to validate

  • rule (Symbol)

    The name of the validation rule to use

  • attributes (Hash) (defaults to: {})
    Optional

    A has containing the validation rule options



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/validation_profiler.rb', line 12

def validates(field, rule, attributes = {})

  if !self.class_variable_defined?(:@@validation_rules)
    self.class_variable_set(:@@validation_rules, [])
  end

  validation_rules = self.class_variable_get(:@@validation_rules)
  validation_rules.push({ name: rule, field: field, attributes: attributes })

  self.class_variable_set(:@@validation_rules, validation_rules)

end