Class: XcodeProject::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/xcodeproject/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Project

Returns a new instance of Project

Raises:



43
44
45
46
47
48
49
50
# File 'lib/xcodeproject/project.rb', line 43

def initialize (path)
  path = Pathname.new(path)
  raise FilePathError.new("No such project file '#{path}'.") unless path.exist?

  @bundle_path = path
  @file_path = bundle_path.join('project.pbxproj')
  @name = bundle_path.basename('.*').to_s
end

Instance Attribute Details

#bundle_pathObject (readonly)

Returns the value of attribute bundle_path



32
33
34
# File 'lib/xcodeproject/project.rb', line 32

def bundle_path
  @bundle_path
end

#file_pathObject (readonly)

Returns the value of attribute file_path



33
34
35
# File 'lib/xcodeproject/project.rb', line 33

def file_path
  @file_path
end

#nameObject (readonly)

Returns the value of attribute name



34
35
36
# File 'lib/xcodeproject/project.rb', line 34

def name
  @name
end

Class Method Details

.find(pattern = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/xcodeproject/project.rb', line 36

def self.find (pattern = nil)
  pattern = Pathname.new(pattern.to_s)
  pattern = pattern.join('*.xcodeproj') if pattern.extname != '.xcodeproj'

  Dir[ pattern ].map {|path| self.new(path) }
end

Instance Method Details

#change {|data| ... } ⇒ Object

Yields:

  • (data)


52
53
54
55
56
# File 'lib/xcodeproject/project.rb', line 52

def change
  data = read
  yield data
  write data
end

#doctorObject



68
69
70
# File 'lib/xcodeproject/project.rb', line 68

def doctor
  change {|data| data.doctor }
end

#readObject



58
59
60
# File 'lib/xcodeproject/project.rb', line 58

def read
  Data.new(JSON.parse(`plutil -convert json -o - "#{file_path}"`), bundle_path.dirname)
end

#write(data) ⇒ Object



62
63
64
65
66
# File 'lib/xcodeproject/project.rb', line 62

def write (data)
  File.open(file_path, "w") do |file|
    file.write(data.to_plist)
  end
end