lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.2.0 vs lib/nanoc/base/entities/identifiable_collection.rb in nanoc-4.2.1
- old
+ new
@@ -1,30 +1,35 @@
module Nanoc::Int
# @api private
class IdentifiableCollection
+ include Nanoc::Int::ContractsSupport
include Enumerable
extend Forwardable
def_delegator :@objects, :each
def_delegator :@objects, :size
def_delegator :@objects, :<<
def_delegator :@objects, :concat
+ # FIXME: use Nanoc::Int::Configuration
+ contract C::Any => C::Any
def initialize(config)
@config = config
@objects = []
end
+ contract C::None => self
def freeze
@objects.freeze
@objects.each(&:freeze)
build_mapping
super
end
+ contract C::Any => C::Maybe[C::RespondTo[:identifier]]
def [](arg)
case arg
when Nanoc::Identifier
object_with_identifier(arg)
when String
@@ -34,19 +39,23 @@
else
raise ArgumentError, "don’t know how to fetch objects by #{arg.inspect}"
end
end
+ contract C::None => C::ArrayOf[C::RespondTo[:identifier]]
def to_a
@objects
end
+ 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
end
protected
def object_with_identifier(identifier)