Class: Compel::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(validator) ⇒ Result

Returns a new instance of Result.



7
8
9
10
11
# File 'lib/compel/result.rb', line 7

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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/compel/result.rb', line 5

def errors
  @errors
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/compel/result.rb', line 5

def value
  @value
end

Instance Method Details

#raise?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/compel/result.rb', line 17

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

    raise exception, 'object has errors'
  end

  value
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/compel/result.rb', line 13

def valid?
  @valid
end