Class: Backframe::Service
- Inherits:
-
Object
- Object
- Backframe::Service
- Defined in:
- lib/backframe/service.rb,
lib/backframe/service/result/base.rb,
lib/backframe/service/result/failure.rb,
lib/backframe/service/result/success.rb
Defined Under Namespace
Modules: Result
Class Method Summary collapse
Instance Method Summary collapse
- #after_commit ⇒ Object
- #after_rollback ⇒ Object
- #before_commit ⇒ Object
- #before_rollback ⇒ Object
- #perform ⇒ Object
Class Method Details
.build(*args) ⇒ Object
9 10 11 |
# File 'lib/backframe/service.rb', line 9 def build(*args) new(*args) end |
.perform(*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/backframe/service.rb', line 13 def perform(*args) service = build(*args) = nil errors = {} result = nil ActiveRecord::Base.transaction do begin result = service.perform rescue StandardError => e = e. # errors = e.errors service.before_rollback raise ActiveRecord::Rollback end service.before_commit end if .nil? service.after_commit else service.after_rollback end return (.present?) ? Result::Failure.new(message: , errors: errors) : Result::Success.new(result) end |
Instance Method Details
#after_commit ⇒ Object
55 56 |
# File 'lib/backframe/service.rb', line 55 def after_commit end |
#after_rollback ⇒ Object
49 50 |
# File 'lib/backframe/service.rb', line 49 def after_rollback end |
#before_commit ⇒ Object
52 53 |
# File 'lib/backframe/service.rb', line 52 def before_commit end |
#before_rollback ⇒ Object
46 47 |
# File 'lib/backframe/service.rb', line 46 def before_rollback end |
#perform ⇒ Object
43 44 |
# File 'lib/backframe/service.rb', line 43 def perform end |