Class: Datum::FormValidator::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/datum/form_validator/entities/attribute.rb

Defined Under Namespace

Classes: ValidationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Attribute

Returns a new instance of Attribute.



12
13
14
15
16
# File 'lib/datum/form_validator/entities/attribute.rb', line 12

def initialize(attrs = {})
  @name = attrs[:name]
  @value = attrs[:value]
  @validations = attrs.fetch(:validations, [])
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



10
11
12
# File 'lib/datum/form_validator/entities/attribute.rb', line 10

def errors
  @errors
end

#formObject

Returns the value of attribute form.



10
11
12
# File 'lib/datum/form_validator/entities/attribute.rb', line 10

def form
  @form
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/datum/form_validator/entities/attribute.rb', line 10

def name
  @name
end

#validationsObject

Returns the value of attribute validations.



10
11
12
# File 'lib/datum/form_validator/entities/attribute.rb', line 10

def validations
  @validations
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/datum/form_validator/entities/attribute.rb', line 10

def value
  @value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/datum/form_validator/entities/attribute.rb', line 18

def valid?
  validate!
  true
rescue ValidationError
  false
end