Sha256: c76854791939d7e98d616a6832b70c98b9c2ab4bff6c10be0ffcc6e8a7822dd6

Contents?: true

Size: 447 Bytes

Versions: 10

Compression:

Stored size: 447 Bytes

Contents

module Compel

  class Result

    attr_reader :value, :errors

    def initialize(validator)
      @valid = validator.valid?
      @value = validator.serialize
      @errors = validator.serialize_errors
    end

    def valid?
      @valid
    end

    def raise?
      if !valid?
        exception = InvalidObjectError.new
        exception.object = value

        raise exception, 'object has errors'
      end

      value
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
compel-0.5.1 lib/compel/result.rb
compel-0.5.0 lib/compel/result.rb
compel-0.4.3 lib/compel/result.rb
compel-0.4.2 lib/compel/result.rb
compel-0.4.0 lib/compel/result.rb
compel-0.3.7 lib/compel/result.rb
compel-0.3.6 lib/compel/result.rb
compel-0.3.4 lib/compel/result.rb
compel-0.3.2 lib/compel/result.rb
compel-0.3.1 lib/compel/result.rb