Class: Alula::DcpResource::ModelErrors
- Inherits:
-
Object
- Object
- 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.
137 138 139 140 |
# File 'lib/alula/dcp_resource.rb', line 137 def initialize(model_class) @model_class = model_class @details = {} end |
Instance Method Details
#[](field_name) ⇒ Object
156 157 158 |
# File 'lib/alula/dcp_resource.rb', line 156 def [](field_name) @details[field_name.to_sym] end |
#add(field_name, error_message) ⇒ Object
152 153 154 |
# File 'lib/alula/dcp_resource.rb', line 152 def add(field_name, ) @details[field_name] = end |
#any? ⇒ Boolean
148 149 150 |
# File 'lib/alula/dcp_resource.rb', line 148 def any? @details.any? end |
#each ⇒ Object
142 143 144 145 146 |
# File 'lib/alula/dcp_resource.rb', line 142 def each @details.each do |field, error| yield({ field => error }) end end |
#full_messages ⇒ Object
160 161 162 |
# File 'lib/alula/dcp_resource.rb', line 160 def @details.map { |field, error| "#{field}: #{error}" } end |
#full_messages_for(attribute_name) ⇒ Object
164 165 166 167 168 |
# File 'lib/alula/dcp_resource.rb', line 164 def (attribute_name) return nil unless @details[attribute_name.to_sym].present? "#{attribute_name}: #{@details[attribute_name.to_sym]}" end |