class Repository::Base::Internals::RecordUpdater
Stows away details of reporting update success/failure. @since 0.0.4
Attributes
dao[R]
factory[R]
identifier[R]
record[R]
updated_attrs[R]
Public Class Methods
new(identifier:, updated_attrs:, dao:, factory:)
click to toggle source
Initializes a new instance of `RecordUpdater`. @param identifier [String] Slug uniquely identifying the record in the
DAO to update
@param updated_attrs
[Hash] Attributes to be updated. @param dao Data Access Object implements persistence without business
logic.
@param factory Class whose `#create` method converts a DAO record to
an entity.
# 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
Public Instance Methods
update()
click to toggle source
Command-pattern method to update a record in the persistence layer, based on the parameters sent to `#initialize`. @return [Repository::Support::StoreResult]
# 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