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)

Returns the attribute that generated the list.

Returns:

  • (Array<Class>)

    the attribute that generated the list.



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

def attribute
  @attribute
end

#ownerArray<Class> (readonly)

Returns the object that owns the list.

Returns:

  • (Array<Class>)

    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.

Parameters:



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.

Parameters:



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.

Parameters:

Returns:



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.

Parameters:

  • from (Fixnum)

    The index of the object.

Returns:



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.

Parameters:



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.

Parameters:



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.

Parameters:

  • from (Fixnum)

    The current index of the object.

  • to (Fixnum)

    The new index for the object.



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

#objectsArray<AbstractObject>

Returns a new array generated with the objects contained in the list.

Returns:

  • (Array<AbstractObject>)

    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.

Parameters:



100
101
102
103
# File 'lib/xcodeproj/project/object_list.rb', line 100

def unshift(object)
  perform_additions_operations(object)
  super
end

#uuidsArray<String>

Returns the UUIDs of all the objects referenced by this list.

Returns:

  • (Array<String>)

    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