Class: Alula::ApiResource::ModelErrors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/alula/api_resource.rb

Instance Method Summary collapse

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, error_message)
  @details[field_name] = error_message
end

#any?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/alula/api_resource.rb', line 179

def any?
  @details.any?
end

#eachObject



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_messagesObject



191
192
193
# File 'lib/alula/api_resource.rb', line 191

def full_messages
  @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 full_messages_for(attribute_name)
  return nil unless @details[attribute_name.to_sym].present?

  "#{attribute_name}: #{@details[attribute_name.to_sym]}"
end