lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.7.4 vs lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.7.5

- old
+ new

@@ -35,10 +35,19 @@ else get_unmemoized(arg) end end + contract C::Any => C::IterOf[C::RespondTo[:identifier]] + def find_all(arg) + if frozen? + find_all_memoized(arg) + else + find_all_unmemoized(arg) + end + end + contract C::None => C::ArrayOf[C::RespondTo[:identifier]] def to_a @objects.to_a end @@ -74,9 +83,21 @@ contract C::Any => C::Maybe[C::RespondTo[:identifier]] def get_memoized(arg) get_unmemoized(arg) end memoize :get_memoized + + contract C::Any => C::IterOf[C::RespondTo[:identifier]] + def find_all_unmemoized(arg) + pat = Nanoc::Int::Pattern.from(arg) + select { |i| pat.match?(i.identifier) } + end + + contract C::Any => C::IterOf[C::RespondTo[:identifier]] + def find_all_memoized(arg) + find_all_unmemoized(arg) + end + memoize :find_all_memoized def object_with_identifier(identifier) if frozen? @mapping[identifier.to_s] else