Class: InformantCommon::Model::Base
- Inherits:
-
Object
- Object
- InformantCommon::Model::Base
- Defined in:
- lib/informant-common/model/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #errors ⇒ Object
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_error(field_name, value, message) ⇒ Object
- #as_json(*_args) ⇒ Object
-
#initialize(id: nil, name: nil, field_errors: []) ⇒ Base
constructor
A new instance of Base.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(id: nil, name: nil, field_errors: []) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 |
# File 'lib/informant-common/model/base.rb', line 7 def initialize(id: nil, name: nil, field_errors: []) self.id = id self.name = name self.errors = field_errors end |
Instance Attribute Details
#errors ⇒ Object
13 14 15 |
# File 'lib/informant-common/model/base.rb', line 13 def errors @errors ||= [] end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/informant-common/model/base.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/informant-common/model/base.rb', line 4 def name @name end |
Instance Method Details
#add_error(field_name, value, message) ⇒ Object
17 18 19 |
# File 'lib/informant-common/model/base.rb', line 17 def add_error(field_name, value, ) errors << FieldError.new(field_name, value, ) end |
#as_json(*_args) ⇒ Object
21 22 23 |
# File 'lib/informant-common/model/base.rb', line 21 def as_json(*_args) { name: name, errors: errors.map(&:as_json) } end |
#to_json(*_args) ⇒ Object
25 26 27 |
# File 'lib/informant-common/model/base.rb', line 25 def to_json(*_args) as_json.to_json end |