Class: Xcodeproj::Project::ObjectList

Inherits:
Array
  • Object
show all
Defined in:
lib/xcodeproj/project/object_list.rb

Overview

TODO:

Cover all the mutations methods of the Array class.

Note:

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

Notification enabled methods collapse

Instance Method Summary collapse

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

#attributeArray<Class> (readonly)


29
30
31
# File 'lib/xcodeproj/project/object_list.rb', line 29

def attribute
  @attribute
end

#ownerArray<Class> (readonly)


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

#clearvoid

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 object at the given given index to the given position.


153
154
155
156
157
158
159
# File 'lib/xcodeproj/project/object_list.rb', line 153

def move(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 given index to the given position.


171
172
173
174
175
176
177
# File 'lib/xcodeproj/project/object_list.rb', line 171

def move_from(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

#objectsArray<AbstractObject>


45
46
47
# File 'lib/xcodeproj/project/object_list.rb', line 45

def objects
  to_a
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

#uuidsArray<String>


38
39
40
# File 'lib/xcodeproj/project/object_list.rb', line 38

def uuids
  map(&:uuid)
end