Class: Base::Operation::Result
- Inherits:
-
Object
- Object
- Base::Operation::Result
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb
Instance Method Summary collapse
- #all_error_messages ⇒ Object
- #error_message ⇒ Object
- #failure? ⇒ Boolean
-
#initialize ⇒ Result
constructor
A new instance of Result.
- #invalid! ⇒ Object
-
#message ⇒ Object
Translated message for use in flash notices and alerts.
- #message_level ⇒ Object
- #model ⇒ Object
- #redirect_path ⇒ Object
- #sub_results ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
6 7 8 9 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 6 def initialize @attrs = {} @forced_invalid = false end |
Instance Method Details
#all_error_messages ⇒ Object
44 45 46 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 44 def errors.map(&:message) end |
#error_message ⇒ Object
40 41 42 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 40 def errors[:base].join(" ") end |
#failure? ⇒ Boolean
32 33 34 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 32 def failure? !success? end |
#invalid! ⇒ Object
36 37 38 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 36 def invalid! @forced_invalid = true end |
#message ⇒ Object
Translated message for use in flash notices and alerts.
49 50 51 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 49 def @attrs.dig(:notice, :text) end |
#message_level ⇒ Object
53 54 55 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 53 def @attrs.dig(:notice, :level) end |
#model ⇒ Object
13 14 15 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 13 def model @attrs[:model] end |
#redirect_path ⇒ Object
17 18 19 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 17 def redirect_path @attrs[:redirect_path] end |
#sub_results ⇒ Object
21 22 23 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 21 def sub_results @attrs[:sub_results] ||= [] end |
#success? ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/generators/tsykvas_rails_template/install/templates/app/concepts/base/operation/result.rb', line 25 def success? return false unless !@forced_invalid && errors.empty? return false unless model.nil? || !model.respond_to?(:errors) ? true : model.errors.empty? sub_results.all?(&:success?) end |