Class: CleanArchitecture::UseCases::Errors
- Inherits:
-
Object
- Object
- CleanArchitecture::UseCases::Errors
- Extended by:
- Forwardable
- Includes:
- ActiveModel::Translation
- Defined in:
- lib/clean_architecture/use_cases/errors.rb
Overview
Acts as a facade in front of ActiveModel::Errors implementing the bare minimum of the API It also implements the same interface as a FailureDetails so as to be interchangeable if passed back to code expecting a FailureDetails
Constant Summary collapse
- DEFAULT_FAILURE_DETAILS_TYPE =
'error'- ATTRIBUTE_NAME_HUMANIZE_OPTIONS =
{ capitalize: true, keep_id_suffix: false }
- BASE_NAME =
:base
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #full_messages ⇒ Object
-
#initialize(base, type = DEFAULT_FAILURE_DETAILS_TYPE) ⇒ Errors
constructor
A new instance of Errors.
- #message ⇒ Object
- #other_properties ⇒ Object
Constructor Details
#initialize(base, type = DEFAULT_FAILURE_DETAILS_TYPE) ⇒ Errors
Returns a new instance of Errors.
18 19 20 21 |
# File 'lib/clean_architecture/use_cases/errors.rb', line 18 def initialize(base, type = DEFAULT_FAILURE_DETAILS_TYPE) @active_model_errors = ActiveModel::Errors.new(base) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/clean_architecture/use_cases/errors.rb', line 23 def type @type end |
Instance Method Details
#full_messages ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/clean_architecture/use_cases/errors.rb', line 45 def @active_model_errors..map do |attribute, | attribute_name = if attribute == BASE_NAME nil else ActiveSupport::Inflector.humanize(attribute, ATTRIBUTE_NAME_HUMANIZE_OPTIONS) end .map { || [attribute_name, ].compact.join(' ') } end.flatten end |
#message ⇒ Object
25 26 27 |
# File 'lib/clean_architecture/use_cases/errors.rb', line 25 def .join(', ') end |
#other_properties ⇒ Object
29 30 31 |
# File 'lib/clean_architecture/use_cases/errors.rb', line 29 def other_properties {} end |