module Scrivito # This class allows you to retrieve obj classes from a specific working copy. It behaves almost # exactly as an Array, so methods like +#each+, +#select+ etc. are available. You can get an # instance by accessing {Workspace#obj_classes}. # # @api public # @deprecated class ObjClassCollection include Enumerable # Initializes an obj class collection for a workspace. # # @param [Workspace] workspace # @return [ObjClassCollection] def initialize(workspace) @workspace = workspace end # Finds an obj class by its name in the working copy of the collection. # # @api public # @deprecated # # @example Find the obj class named "Homepage" in the "rtc" {Workspace}. # Workspace.find('rtc').obj_classes['Homepage'] # # @param [String] name The name of the obj class. # @return [ObjClass, nil] Returns the obj class or nil when no obj class with the given +name+ can be found in the working copy. def [](name) if obj_class_data = CmsBackend.instance.find_obj_class_data_by_name(workspace.revision, name) ObjClass.new(obj_class_data, workspace) end end # # @!method each # # Yields successive obj classes of the collection. Implements the +Enumerable+ interface. # # @api public # @deprecated # @see Scrivito::ObjClass.remove # # @yield [ObjClass] successive obj classes of the collection if the corresponding workspace # still uses {Scrivito::ObjClass}. # @yield [Array] an empty array if the corresponding workspace does not use {Scrivito::ObjClass} # anymore. # # @example Find all obj classes in the "rtc" {Workspace} and print their name. # Workspace.find('rtc').obj_classes.each do |obj_class| # puts obj_class.name # end # delegate :each, to: :obj_classes private def obj_classes if workspace.uses_obj_classes CmsBackend.instance.find_all_obj_class_data(workspace.revision).map do |obj_class_data| ObjClass.new(obj_class_data, workspace) end else Scrivito.print_obj_class_deprecated_warning [] end end attr_reader :workspace end end