lib/phlexi/field/structure/namespace_collection.rb in phlexi-field-0.0.7 vs lib/phlexi/field/structure/namespace_collection.rb in phlexi-field-0.0.8

- old
+ new

@@ -14,21 +14,32 @@ @collection = collection @block = block each(&block) end + def object + @collection + end + private def each(&) namespaces.each(&) end # Builds and memoizes namespaces for the collection. # # @return [Array<Namespace>] An array of namespace objects. def namespaces - @namespaces ||= @collection.map.with_index do |object, key| - build_namespace(key, object: object) + @namespaces ||= case @collection + when Hash + @collection.map do |key, object| + build_namespace(key, object: object) + end + when Array + @collection.map.with_index do |object, key| + build_namespace(key, object: object) + end end end def build_namespace(index, **) parent.class.new(index, parent: self, builder_klass: parent.builder_klass, **)