class Cuprum::Collections::Errors::NotFound
Returned when a find command does not find the requested items.
Constants
- TYPE
Short string used to identify the type of error.
Attributes
collection_name[R]
@return [String, Symbol] the name of the collection.
primary_key_name[R]
@return [String, Symbol] the name of the primary key attribute.
primary_key_values[R]
@return [Array] The expected values of the primary key attribute.
Public Class Methods
new(collection_name:, primary_key_name:, primary_key_values:)
click to toggle source
@param collection_name
[String, Symbol] The name of the collection. @param primary_key_name
[String, Symbol] The name of the primary key
attribute.
@param primary_key_values
[Object, Array] The expected values of the
primary key attribute.
Calls superclass method
# File lib/cuprum/collections/errors/not_found.rb, line 19 def initialize(collection_name:, primary_key_name:, primary_key_values:) @collection_name = collection_name @primary_key_name = primary_key_name @primary_key_values = Array(primary_key_values) super(message: default_message) end
Public Instance Methods
as_json()
click to toggle source
@return [Hash] a serializable hash representation of the error.
# File lib/cuprum/collections/errors/not_found.rb, line 37 def as_json { 'data' => { 'collection_name' => collection_name, 'primary_key_name' => primary_key_name, 'primary_key_values' => primary_key_values }, 'message' => message, 'type' => type } end
type()
click to toggle source
@return [String] short string used to identify the type of error.
# File lib/cuprum/collections/errors/not_found.rb, line 50 def type TYPE end
Private Instance Methods
default_message()
click to toggle source
# File lib/cuprum/collections/errors/not_found.rb, line 56 def default_message primary_keys = primary_key_values.map(&:inspect).join(', ') "#{entity_name} not found with #{primary_key_name} #{primary_keys}" end
entity_name()
click to toggle source
# File lib/cuprum/collections/errors/not_found.rb, line 62 def entity_name entity_name = collection_name entity_name = tools.str.singularize(entity_name) if singular? titleize(entity_name) end
singular?()
click to toggle source
# File lib/cuprum/collections/errors/not_found.rb, line 69 def singular? primary_key_values.size == 1 end
titleize(string)
click to toggle source
# File lib/cuprum/collections/errors/not_found.rb, line 73 def titleize(string) tools.str.underscore(string).split('_').map(&:capitalize).join(' ') end
tools()
click to toggle source
# File lib/cuprum/collections/errors/not_found.rb, line 77 def tools SleepingKingStudios::Tools::Toolbelt.instance end