Class: Repository::Base::Internals::RecordUpdater
- Inherits:
-
Object
- Object
- Repository::Base::Internals::RecordUpdater
- Includes:
- Support
- Defined in:
- lib/repository/base/internals/record_updater.rb
Overview
Stows away details of reporting update success/failure.
Instance Attribute Summary collapse
- #dao ⇒ Object readonly private
- #factory ⇒ Object readonly private
- #identifier ⇒ Object readonly private
- #record ⇒ Object readonly private
- #updated_attrs ⇒ Object readonly private
Instance Method Summary collapse
-
#failed_result ⇒ Object
private
:nodoc:.
-
#initialize(identifier:, updated_attrs:, dao:, factory:) ⇒ RecordUpdater
constructor
Initializes a new instance of `RecordUpdater`.
-
#successful_result ⇒ Object
private
:nodoc:.
-
#update ⇒ Repository::Support::StoreResult
Command-pattern method to update a record in the persistence layer, based on the parameters sent to `#initialize`.
Constructor Details
#initialize(identifier:, updated_attrs:, dao:, factory:) ⇒ RecordUpdater
Initializes a new instance of `RecordUpdater`.
23 24 25 26 27 28 |
# File 'lib/repository/base/internals/record_updater.rb', line 23 def initialize(identifier:, updated_attrs:, dao:, factory:) @identifier = identifier @updated_attrs = updated_attrs @dao = dao @factory = factory end |
Instance Attribute Details
#dao ⇒ Object (readonly, private)
41 42 43 |
# File 'lib/repository/base/internals/record_updater.rb', line 41 def dao @dao end |
#factory ⇒ Object (readonly, private)
41 42 43 |
# File 'lib/repository/base/internals/record_updater.rb', line 41 def factory @factory end |
#identifier ⇒ Object (readonly, private)
41 42 43 |
# File 'lib/repository/base/internals/record_updater.rb', line 41 def identifier @identifier end |
#record ⇒ Object (readonly, private)
41 42 43 |
# File 'lib/repository/base/internals/record_updater.rb', line 41 def record @record end |
#updated_attrs ⇒ Object (readonly, private)
41 42 43 |
# File 'lib/repository/base/internals/record_updater.rb', line 41 def updated_attrs @updated_attrs end |
Instance Method Details
#failed_result ⇒ Object (private)
:nodoc:
43 44 45 |
# File 'lib/repository/base/internals/record_updater.rb', line 43 def failed_result # :nodoc: StoreResult::Failure.new record.errors end |
#successful_result ⇒ Object (private)
:nodoc:
47 48 49 50 |
# File 'lib/repository/base/internals/record_updater.rb', line 47 def successful_result # :nodoc: entity = factory.create record StoreResult::Success.new entity end |
#update ⇒ Repository::Support::StoreResult
Command-pattern method to update a record in the persistence layer, based on the parameters sent to `#initialize`.
33 34 35 36 37 |
# File 'lib/repository/base/internals/record_updater.rb', line 33 def update @record = dao.where(slug: identifier).first return failed_result unless @record.update(updated_attrs.to_h) successful_result end |