Class: Alula::DcpResource::ModelErrors
- Includes:
- Enumerable
- Defined in:
- lib/alula/dcp_resource.rb
Overview
Class for holding model errors
Instance Method Summary collapse
- #[](field_name) ⇒ Object
- #add(field_name, error_message) ⇒ Object
- #any? ⇒ Boolean
- #each ⇒ Object
- #full_messages ⇒ Object
- #full_messages_for(attribute_name) ⇒ Object
-
#initialize(model_class) ⇒ ModelErrors
constructor
A new instance of ModelErrors.
Constructor Details
#initialize(model_class) ⇒ ModelErrors
Returns a new instance of ModelErrors.
203 204 205 206 |
# File 'lib/alula/dcp_resource.rb', line 203 def initialize(model_class) @model_class = model_class @details = {} end |
Instance Method Details
#[](field_name) ⇒ Object
222 223 224 |
# File 'lib/alula/dcp_resource.rb', line 222 def [](field_name) @details[field_name.to_sym] end |
#add(field_name, error_message) ⇒ Object
218 219 220 |
# File 'lib/alula/dcp_resource.rb', line 218 def add(field_name, ) @details[field_name] = end |
#any? ⇒ Boolean
214 215 216 |
# File 'lib/alula/dcp_resource.rb', line 214 def any? @details.any? end |
#each ⇒ Object
208 209 210 211 212 |
# File 'lib/alula/dcp_resource.rb', line 208 def each @details.each do |field, error| yield({ field => error }) end end |
#full_messages ⇒ Object
226 227 228 |
# File 'lib/alula/dcp_resource.rb', line 226 def @details.map { |field, error| "#{field}: #{error}" } end |
#full_messages_for(attribute_name) ⇒ Object
230 231 232 233 234 |
# File 'lib/alula/dcp_resource.rb', line 230 def (attribute_name) return nil unless @details[attribute_name.to_sym].present? "#{attribute_name}: #{@details[attribute_name.to_sym]}" end |