lib/nanoc/base/source_data/item_array.rb in nanoc-3.8.0 vs lib/nanoc/base/source_data/item_array.rb in nanoc-4.0.0a1

- old
+ new

@@ -1,9 +1,11 @@ # encoding: utf-8 -module Nanoc +module Nanoc::Int # Acts as an array, but allows fetching items using identifiers, e.g. `@items['/blah/']`. + # + # @api private class ItemArray include Enumerable extend Forwardable @@ -31,11 +33,11 @@ def [](*args) if 1 == args.size && args.first.is_a?(String) item_with_identifier(args.first) elsif 1 == args.size && args.first.is_a?(Regexp) - @items.select { |i| i.identifier =~ args.first } + @items.select { |i| i.identifier.to_s =~ args.first } else @items[*args] end end alias_method :slice, :[] @@ -50,19 +52,19 @@ protected def item_with_identifier(identifier) if self.frozen? - @mapping[identifier] + @mapping[identifier.to_s] else @items.find { |i| i.identifier == identifier } end end def build_mapping @mapping = {} @items.each do |item| - @mapping[item.identifier] = item + @mapping[item.identifier.to_s] = item end @mapping.freeze end end end