Class: MuchRails::ChangeActionResult
- Inherits:
-
Object
- Object
- MuchRails::ChangeActionResult
show all
- Defined in:
- lib/much-rails/change_action_result.rb
Overview
MuchRails::ChangeActionResult is a Result object intended to wrap and compose a MuchRails::Result.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ChangeActionResult.
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/much-rails/change_action_result.rb', line 20
def initialize(save_service_result)
unless save_service_result.is_a?(MuchRails::Result)
raise(
TypeError,
"MuchRails::Result expected, got #{save_service_result.class}",
)
end
@service_result = save_service_result
@service_result.validation_errors ||= HashWithIndifferentAccess.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
55
56
57
|
# File 'lib/much-rails/change_action_result.rb', line 55
def method_missing(name, *args, &block)
service_result&.__send__(name, *args, &block)
end
|
Instance Attribute Details
#service_result ⇒ Object
Returns the value of attribute service_result.
18
19
20
|
# File 'lib/much-rails/change_action_result.rb', line 18
def service_result
@service_result
end
|
Class Method Details
.failure(**kargs) ⇒ Object
14
15
16
|
# File 'lib/much-rails/change_action_result.rb', line 14
def self.failure(**kargs)
new(MuchRails::Result.failure(**kargs))
end
|
.success(**kargs) ⇒ Object
10
11
12
|
# File 'lib/much-rails/change_action_result.rb', line 10
def self.success(**kargs)
new(MuchRails::Result.success(**kargs))
end
|
Instance Method Details
49
50
51
|
# File 'lib/much-rails/change_action_result.rb', line 49
def
!!(failure? && validation_errors.any?)
end
|
45
46
47
|
# File 'lib/much-rails/change_action_result.rb', line 45
def (field_name)
Array.wrap(validation_errors.delete(field_name)).compact
end
|
#validation_error_messages ⇒ Object
41
42
43
|
# File 'lib/much-rails/change_action_result.rb', line 41
def validation_error_messages
validation_errors.values.flatten.compact
end
|
#validation_errors ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/much-rails/change_action_result.rb', line 33
def validation_errors
@validation_errors ||=
service_result
.get_for_all_results(:validation_errors)
.to_h
.with_indifferent_access
end
|