lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.7.12 vs lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.7.13

- old
+ new

@@ -10,20 +10,21 @@ extend Forwardable def_delegator :@objects, :each def_delegator :@objects, :size - contract C::Or[Hash, C::Named['Nanoc::Int::Configuration']], C::IterOf[C::RespondTo[:identifier]] => C::Any - def initialize(config, objects = []) + def initialize(*) + raise 'IdentifiableCollection is abstract and cannot be instantiated' + end + + contract C::Or[Hash, C::Named['Nanoc::Int::Configuration']], C::IterOf[C::RespondTo[:identifier]], C::Maybe[String] => C::Any + def initialize_basic(config, objects = [], name = nil) @config = config @objects = Hamster::Vector.new(objects) + @name = name end - def self.from(enum, config) - new(config, enum) - end - contract C::None => self def freeze @objects.freeze @objects.each(&:freeze) build_mapping @@ -56,18 +57,21 @@ contract C::None => C::Bool def empty? @objects.empty? end + contract C::RespondTo[:identifier] => self def add(obj) self.class.new(@config, @objects.add(obj)) end + contract C::Func[C::RespondTo[:identifier] => C::Any] => self def reject(&block) self.class.new(@config, @objects.reject(&block)) end + contract C::Any => C::Maybe[C::RespondTo[:identifier]] def object_with_identifier(identifier) if frozen? @mapping[identifier.to_s] else @objects.find { |i| i.identifier == identifier } @@ -121,9 +125,10 @@ @mapping[object.identifier.to_s] = object end @mapping.freeze end + contract C::None => C::Bool def use_globs? @config[:string_pattern_type] == 'glob' end end end