Module: ErrorProne::Validator::ClassMethods

Defined in:
lib/error_prone.rb

Instance Method Summary collapse

Instance Method Details

#rulesErrorProne::RuleSet

Contains rules the validator will run when .validate! is called

Returns:



133
134
135
# File 'lib/error_prone.rb', line 133

def rules
  @rules ||= RuleSet.new
end

#validate!(object) ⇒ Boolean

Validates all rules against the given object

Parameters:

  • object (Object)

    Object to validate each rule against

Returns:

  • (Boolean)

    True if all rules are valid, false otherwise.



151
152
153
# File 'lib/error_prone.rb', line 151

def validate!(object)
  rules.all_valid_for? object
end

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

Adds a rule the validator runs when .validate! is called.

Parameters:

  • field (Symbol)

    Method to call on the object to validate

  • rule (Symbol)

    Name of rule to apply, defined by Rule.validates_as

  • options (Hash) (defaults to: {})

    to pass to the Rule when instantiating



143
144
145
# File 'lib/error_prone.rb', line 143

def validates(field, rule, options={})
  rules.add(field, rule, options)
end