Class: Rubee::Validatable::State

Inherits:
Object
  • Object
show all
Defined in:
lib/rubee/extensions/validatable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



8
9
10
11
# File 'lib/rubee/extensions/validatable.rb', line 8

def initialize
  @valid = true
  @errors = {}
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



6
7
8
# File 'lib/rubee/extensions/validatable.rb', line 6

def errors
  @errors
end

#validObject

Returns the value of attribute valid.



6
7
8
# File 'lib/rubee/extensions/validatable.rb', line 6

def valid
  @valid
end

Instance Method Details

#add_error(attribute, hash) ⇒ Object



13
14
15
16
17
# File 'lib/rubee/extensions/validatable.rb', line 13

def add_error(attribute, hash)
  @valid = false
  @errors[attribute] ||= {}
  @errors[attribute].merge!(hash)
end

#has_errors_for?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rubee/extensions/validatable.rb', line 19

def has_errors_for?(attribute)
  @errors.key?(attribute)
end