lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.6.1 vs lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.6.2

- old
+ new

@@ -6,18 +6,19 @@ extend Forwardable def_delegator :@objects, :each def_delegator :@objects, :size - def_delegator :@objects, :<< - def_delegator :@objects, :concat - contract C::Or[Hash, C::Named['Nanoc::Int::Configuration']] => C::Any - def initialize(config) + contract C::Or[Hash, C::Named['Nanoc::Int::Configuration']], C::IterOf[C::RespondTo[:identifier]] => C::Any + def initialize(config, objects = []) @config = config + @objects = objects + end - @objects = [] + def self.from(enum, config) + new(config, enum) end contract C::None => self def freeze @objects.freeze @@ -48,13 +49,15 @@ contract C::None => C::Bool def empty? @objects.empty? end - contract C::Func[C::RespondTo[:identifier] => C::Bool] => self - def delete_if(&block) - @objects.delete_if(&block) - self + def add(obj) + self.class.new(@config, @objects + [obj]) + end + + def reject(&block) + self.class.new(@config, @objects.reject(&block)) end protected def object_with_identifier(identifier)