Module: Ohm::Validations

Included in:
Model::Validations
Defined in:
lib/ohm/validations.rb

Defined Under Namespace

Classes: Errors, Presenter

Instance Method Summary (collapse)

Instance Method Details

- (Object) assert(value, error) (protected)



93
94
95
# File 'lib/ohm/validations.rb', line 93

def assert(value, error)
  value or errors.push(error) && false
end

- (Object) assert_format(att, format, error = [att, :format]) (protected)



77
78
79
80
81
# File 'lib/ohm/validations.rb', line 77

def assert_format(att, format, error = [att, :format])
  if assert_present(att, error)
    assert(send(att).to_s.match(format), error)
  end
end

- (Object) assert_numeric(att, error = [att, :not_numeric]) (protected)



87
88
89
90
91
# File 'lib/ohm/validations.rb', line 87

def assert_numeric(att, error = [att, :not_numeric])
  if assert_present(att, error)
    assert_format(att, /^\d+$/, error)
  end
end

- (Object) assert_present(att, error = [att, :not_present]) (protected)



83
84
85
# File 'lib/ohm/validations.rb', line 83

def assert_present(att, error = [att, :not_present])
  assert(!send(att).to_s.empty?, error)
end

- (Object) errors



71
72
73
# File 'lib/ohm/validations.rb', line 71

def errors
  @errors ||= Errors.new(self)
end

- (Boolean) valid?

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/ohm/validations.rb', line 62

def valid?
  errors.clear
  validate
  errors.empty?
end

- (Object) validate



68
69
# File 'lib/ohm/validations.rb', line 68

def validate
end