Class: Alula::ApiResource::ModelErrors
- Inherits:
-
Object
- Object
- Alula::ApiResource::ModelErrors
- Includes:
- Enumerable
- Defined in:
- lib/alula/api_resource.rb
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.
168 169 170 171 |
# File 'lib/alula/api_resource.rb', line 168 def initialize(model_class) @model_class = model_class @details = {} end |
Instance Method Details
#[](field_name) ⇒ Object
187 188 189 |
# File 'lib/alula/api_resource.rb', line 187 def [](field_name) @details[field_name.to_sym] end |
#add(field_name, error_message) ⇒ Object
183 184 185 |
# File 'lib/alula/api_resource.rb', line 183 def add(field_name, ) @details[field_name] = end |
#any? ⇒ Boolean
179 180 181 |
# File 'lib/alula/api_resource.rb', line 179 def any? @details.any? end |
#each ⇒ Object
173 174 175 176 177 |
# File 'lib/alula/api_resource.rb', line 173 def each @details.each do |field, error| yield({ field => error }) end end |
#full_messages ⇒ Object
191 192 193 |
# File 'lib/alula/api_resource.rb', line 191 def @details.map { |field, error| "#{field}: #{error}" } end |
#full_messages_for(attribute_name) ⇒ Object
195 196 197 198 199 |
# File 'lib/alula/api_resource.rb', line 195 def (attribute_name) return nil unless @details[attribute_name.to_sym].present? "#{attribute_name}: #{@details[attribute_name.to_sym]}" end |