Sha256: 8f6a610f8c638d4049ad7f25c6633c2705f06190695851871513b61089378e7b
Contents?: true
Size: 1.76 KB
Versions: 20
Compression:
Stored size: 1.76 KB
Contents
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 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 # # @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 # @yield [ObjClass] Successive obj classes of the collection. # @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 CmsBackend.instance.find_all_obj_class_data(workspace.revision).map do |obj_class_data| ObjClass.new(obj_class_data, workspace) end end attr_reader :workspace end end
Version data entries
20 entries across 20 versions & 1 rubygems