class DomainModel::Validator::Scalar
Attributes
value[R]
Public Class Methods
new(field, value)
click to toggle source
# File lib/domain_model.rb, line 347 def initialize(field, value) @field, @value = field, value end
Public Instance Methods
errors()
click to toggle source
# File lib/domain_model.rb, line 351 def errors case when legitimately_empty? [] when (value.nil? and field.required?) ["cannot be nil"] when type_mismatch? ["is not an instance of #{type_string} (was #{value.class.inspect})"] when transitively_invalid? ["is invalid"] else [] end end
Private Instance Methods
legitimately_empty?()
click to toggle source
# File lib/domain_model.rb, line 378 def legitimately_empty? value.nil? and not field.required? end
transitively_invalid?()
click to toggle source
# File lib/domain_model.rb, line 382 def transitively_invalid? field.validate? and not value.valid? end
type_mismatch?()
click to toggle source
# File lib/domain_model.rb, line 370 def type_mismatch? types.none? { |t| value.is_a?(t) } end
type_string()
click to toggle source
# File lib/domain_model.rb, line 374 def type_string types.map(&:inspect).join(' or ') end