class Xcunique::Sorter

Sorter traverses the objects in the project and sorts keys that are listed in the `SORTABLE_ITEMS` array

Constants

SORTABLE_ITEMS

The keys within the project that should be supported

UNSUPPORTED_SORTABLE_ITEMS

Keys that could be sorted in future

Attributes

objects[RW]
project[RW]

Public Class Methods

new(project) click to toggle source

Returns a new instance of Sorter

@param project [Hash] the project to sort

# File lib/xcunique/sorter.rb, line 15
def initialize project
  @project = project.deep_dup
  @objects = @project[Keys::OBJECTS]
end

Public Instance Methods

sort() click to toggle source

Traverses the objects in the project clone and sorts in place objects that are held under the `SORTABLE_ITEMS` keys

@return [Hash] a sorted project

# File lib/xcunique/sorter.rb, line 24
def sort
  objects.values.each do |object|
    SORTABLE_ITEMS.select { |key| object.has_key?(key) }.each do |key|
      object[key].sort_by!(&method(:comparator))
    end
  end
  project
end

Private Instance Methods

comparator(uuid) click to toggle source

The comparator used during the sort

The comparator resolves the attributes for the node and appends a known prefix to objects where `isa = PBXGroup` to ensure that groups are sorted above files

@param uuid [String] the uuid of the object to examine @!visibility public

# File lib/xcunique/sorter.rb, line 45
def comparator uuid
  prefix = objects[uuid][Keys::ISA] == Keys::PBXGroup ? '  ' : ''
  prefix + Helpers.resolve_attributes(uuid, objects)
end