Sha256: 32928ca001c5085f91ab477c0d134ccc28bb556f156857112e7501f7d1f77776

Contents?: true

Size: 619 Bytes

Versions: 2

Compression:

Stored size: 619 Bytes

Contents

module Ohm
  module Validations
    def valid?
      errors.clear
      validate
      errors.empty?
    end

    def validate
    end

    def errors
      @errors ||= []
    end

  protected

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

    def assert_present(att)
      if assert_not_nil(att)
        assert !send(att).empty?, [att, :empty]
      end
    end

    def assert_not_nil(att)
      assert send(att), [att, :nil]
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ohm-0.0.5 lib/ohm/validations.rb
ohm-0.0.4 lib/ohm/validations.rb