Class: RS::Validable

Inherits:
Object
  • Object
show all
Defined in:
lib/rs/models/waybill.rb

Overview

Class with errors and warnings.

Direct Known Subclasses

Waybill, WaybillItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



6
7
8
# File 'lib/rs/models/waybill.rb', line 6

def errors
  @errors
end

#warningsObject

Returns the value of attribute warnings.



6
7
8
# File 'lib/rs/models/waybill.rb', line 6

def warnings
  @warnings
end

Instance Method Details

#add_error(fld, msg) ⇒ Object

Add error to the specified field.



9
10
11
12
# File 'lib/rs/models/waybill.rb', line 9

def add_error(fld, msg)
  self.errors = {} unless self.errors
  self.errors[fld.to_sym] = msg
end

#add_warning(fld, msg) ⇒ Object

Add warning to the specified field.



15
16
17
18
# File 'lib/rs/models/waybill.rb', line 15

def add_warning(fld, msg)
  self.warnings = {} unless self.warnings
  self.warnings[fld.to_sym] = msg
end

#valid?Boolean

Valid?

Returns:

  • (Boolean)


21
22
23
# File 'lib/rs/models/waybill.rb', line 21

def valid?
  self.errors.nil? or self.errors.empty?
end