Class: Xcodeproj::Pbxproj::PbxObject::PbxWrite

Inherits:
Object
  • Object
show all
Defined in:
lib/xsort/xcodeproj/pbxproj/pbxobject/PbxWrite.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, pbx, stdout, write) ⇒ PbxWrite

Returns a new instance of PbxWrite.



18
19
20
21
22
23
# File 'lib/xsort/xcodeproj/pbxproj/pbxobject/PbxWrite.rb', line 18

def initialize(path,pbx, stdout,write)
    @pbx = pbx
    @stdout = stdout
    @path = path
    @write = write
end

Instance Method Details

#overWriteObject

We will overwrite the pbxobject that re-sorted Xcode’s xcodeproj into a file.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/xsort/xcodeproj/pbxproj/pbxobject/PbxWrite.rb', line 28

def overWrite
    isPbxGroup = false
    pbxValue = ""
    num = 0
    isSuccess = true
    begin
        File.open(@path, "r") do |pbx|
            pbx.each_line do |pbx_line|

                if pbx_line.index("/* End PBXGroup section */")
                    sorted = @pbx.join
                    sorted << pbx_line
                    pbx_line = sorted
                    isPbxGroup = false
                end

                if isPbxGroup == true
                    pbx_line = ""
                end

                if pbx_line.index("/* Begin PBXGroup section */")
                    isPbxGroup = true
                end

                pbxValue << pbx_line
            end
        end

        if @stdout == true
            puts pbxValue
        end

        writeFile(pbxValue)

    rescue IOError => ioerr
        isSuccess = false
        puts "Error \e[31m#{ioerr.message}\e[0m"
    rescue SystemCallError => sysCallErr
        isSuccess = false
        puts "Failuer! reason: \n\e[31m#{sysCallErr.message}\e[0m"
        puts "The entered path is invalid."
    end
    if isSuccess == true
        puts "\e[36mXsort Successful (☝ ՞ਊ ՞)☝!!!\e[0m"
    end
end

#writeFile(value) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/xsort/xcodeproj/pbxproj/pbxobject/PbxWrite.rb', line 75

def writeFile(value)
    if @write == true
        @path = "./output.pbxproj"
    end
    File.open(@path,"w") do |write|
        write.puts(value)
    end
end