Class: Xcodeproj::Project::ObjectList
- Inherits:
-
Array
- Object
- Array
- Xcodeproj::Project::ObjectList
- Defined in:
- lib/xcodeproj/project/object_list.rb
Overview
Cover all the mutations methods of the Array class.
Concerning the mutations methods it is safe to call only those which are overridden to inform objects reference count. Ideally all the array methods should be covered, but this is not done yet. Moreover it is a moving target because the methods of array usually are implemented in C
This class represents an ordered relationship to many objects.
It works in conjunction with the Xcodeproj::Project::Object::AbstractObject class to ensure that the project is not serialized with unreachable objects by updating the with reference count on modifications.
Instance Attribute Summary collapse
-
#attribute ⇒ Array<Class>
readonly
The attribute that generated the list.
-
#owner ⇒ Array<Class>
readonly
The object that owns the list.
Notification enabled methods collapse
-
#+(other) ⇒ void
Adds an array of objects to list and updates their references count.
-
#<<(object) ⇒ void
Appends an object to list the and updates its references count.
-
#clear ⇒ void
Removes all the objects contained in the list and updates their reference counts.
-
#delete(object) ⇒ AbstractObject, ...
Removes an object to list and updates its references count.
-
#delete_at(index) ⇒ AbstractObject, ...
Removes the object at the given index from the list and updates its references count.
-
#insert(index, object) ⇒ void
Adds an object to the given index of the list the and updates its references count.
-
#move(object, new_index) ⇒ void
Moves the given object to the given index.
-
#move_from(current_index, new_index) ⇒ void
Moves the object at the given index to the given position.
- #sort! ⇒ Object
-
#unshift(object) ⇒ void
Prepends an object to the list and updates its references count.
Instance Method Summary collapse
-
#initialize(attribute, owner) ⇒ ObjectList
constructor
Xcodeproj clients are not expected to create instances of ObjectList, it is always initialized empty and automatically by the synthesized methods generated by Xcodeproj::Project::Object::AbstractObject.has_many.
-
#objects ⇒ Array<AbstractObject>
A new array generated with the objects contained in the list.
-
#uuids ⇒ Array<String>
The UUIDs of all the objects referenced by this list.
Constructor Details
#initialize(attribute, owner) ⇒ ObjectList
Xcodeproj clients are not expected to create instances of Xcodeproj::Project::ObjectList, it is always initialized empty and automatically by the synthesized methods generated by Xcodeproj::Project::Object::AbstractObject.has_many.
22 23 24 25 |
# File 'lib/xcodeproj/project/object_list.rb', line 22 def initialize(attribute, owner) @attribute = attribute @owner = owner end |
Instance Attribute Details
#attribute ⇒ Array<Class> (readonly)
Returns the attribute that generated the list.
29 30 31 |
# File 'lib/xcodeproj/project/object_list.rb', line 29 def attribute @attribute end |
#owner ⇒ Array<Class> (readonly)
Returns the object that owns the list.
33 34 35 |
# File 'lib/xcodeproj/project/object_list.rb', line 33 def owner @owner end |
Instance Method Details
#+(other) ⇒ void
This method returns an undefined value.
Adds an array of objects to list and updates their references count.
63 64 65 66 |
# File 'lib/xcodeproj/project/object_list.rb', line 63 def +(other) perform_additions_operations(other) super end |
#<<(object) ⇒ void
This method returns an undefined value.
Appends an object to list the and updates its references count.
75 76 77 78 |
# File 'lib/xcodeproj/project/object_list.rb', line 75 def <<(object) perform_additions_operations(object) super end |
#clear ⇒ void
This method returns an undefined value.
Removes all the objects contained in the list and updates their reference counts.
136 137 138 139 140 141 |
# File 'lib/xcodeproj/project/object_list.rb', line 136 def clear objects.each do |object| perform_deletion_operations(object) end super end |
#delete(object) ⇒ AbstractObject, ...
Removes an object to list and updates its references count.
112 113 114 115 |
# File 'lib/xcodeproj/project/object_list.rb', line 112 def delete(object) perform_deletion_operations(object) super end |
#delete_at(index) ⇒ AbstractObject, ...
Removes the object at the given index from the list and updates its references count.
125 126 127 128 129 |
# File 'lib/xcodeproj/project/object_list.rb', line 125 def delete_at(index) object = at(index) perform_deletion_operations(object) super end |
#insert(index, object) ⇒ void
This method returns an undefined value.
Adds an object to the given index of the list the and updates its references count.
88 89 90 91 |
# File 'lib/xcodeproj/project/object_list.rb', line 88 def insert(index, object) perform_additions_operations(object) super end |
#move(object, new_index) ⇒ void
This method returns an undefined value.
Moves the given object to the given index.
153 154 155 156 157 158 159 160 |
# File 'lib/xcodeproj/project/object_list.rb', line 153 def move(object, new_index) return if index(object) == new_index if obj = delete(object) insert(new_index, obj) else raise "Attempt to move object `#{object}` not present in the list `#{inspect}`" end end |
#move_from(current_index, new_index) ⇒ void
This method returns an undefined value.
Moves the object at the given index to the given position.
172 173 174 175 176 177 178 179 |
# File 'lib/xcodeproj/project/object_list.rb', line 172 def move_from(current_index, new_index) return if current_index == new_index if obj = delete_at(current_index) insert(new_index, obj) else raise "Attempt to move object from index `#{current_index}` which is beyond bounds of the list `#{inspect}`" end end |
#objects ⇒ Array<AbstractObject>
Returns a new array generated with the objects contained in the list.
45 46 47 |
# File 'lib/xcodeproj/project/object_list.rb', line 45 def objects to_a end |
#sort! ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/xcodeproj/project/object_list.rb', line 181 def sort! return super if owner.project.dirty? previous = to_a super owner.mark_project_as_dirty! unless previous == to_a self end |
#unshift(object) ⇒ void
This method returns an undefined value.
Prepends an object to the list and updates its references count.
100 101 102 103 |
# File 'lib/xcodeproj/project/object_list.rb', line 100 def unshift(object) perform_additions_operations(object) super end |
#uuids ⇒ Array<String>
Returns the UUIDs of all the objects referenced by this list.
38 39 40 |
# File 'lib/xcodeproj/project/object_list.rb', line 38 def uuids map(&:uuid) end |