lib/shamu/services/service.rb in shamu-0.0.13 vs lib/shamu/services/service.rb in shamu-0.0.14
- old
+ new
@@ -99,24 +99,32 @@
# records )` that maps a set of records to their corresponding
# entities.
#
# @param [Enumerable] records the raw list of records.
# @yield (record)
- # @yieldparam [Object] record the raw value from the `list` to to
+ # @yieldparam [Enumerable<Object>] records the raw values from the `list` to
# transform to an {Entities::Entity}.
# @yieldreturn [Entities::Entity]
# @return [Entities::List]
def entity_list( records, &transformer )
return Entities::List.new [] unless records
unless transformer
fail "Either provide a block or add a private method `def build_entities( records )` to #{ self.class.name }." unless respond_to?( :build_entities, true ) # rubocop:disable Metrics/LineLength
transformer ||= method( :build_entities )
end
- Entities::List.new LazyTransform.new( records, &transformer )
+ build_entity_list build_records_transform( records, &transformer )
end
+ def build_records_transform( records, &transformer )
+ LazyTransform.new( records, &transformer )
+ end
+
+ def build_entity_list( source )
+ Entities::List.new source
+ end
+
# @!visibility public
# Match a list of records with the ids used to look up those records.
# Uses a {Entities::NullEntity} if the id doesn't have a matching record.
#
# @param [Enumerable] records matching the requested `ids`.
@@ -217,10 +225,10 @@
end
# @!visibility public
#
# Find an associated entity from a dependent service. Attempts to
- # effeciently handle multiple requests to lookup associations by caching
+ # efficiently handle multiple requests to lookup associations by caching
# all the associated entities when {#lookup_association} is used
# repeatedly when building an entity.
#
# @param [Object] id of the associated {Entities::Entity} to find.
# @param [Service] service used to locate the associated resource.