Class: XcodeProject::RootNode
- Inherits:
-
Object
- Object
- XcodeProject::RootNode
- Defined in:
- lib/xcodeproject/root_node.rb
Instance Method Summary collapse
- #absolute_path(path) ⇒ Object
- #add_object(data) ⇒ Object
- #build_files(file_ref_uuid) ⇒ Object
- #find_object(isa, hash = Hash.new) ⇒ Object
- #find_object!(isa, hash = Hash.new) ⇒ Object
- #find_object2(isa, h1 = Hash.new, h2 = Hash.new) ⇒ Object
- #find_object2!(isa, h1 = Hash.new, h2 = Hash.new) ⇒ Object
- #find_objects(isa, hash = Hash.new) ⇒ Object
- #find_objects!(isa, hash = Hash.new) ⇒ Object
- #generate_object_uuid ⇒ Object
-
#initialize(data, wd) ⇒ RootNode
constructor
A new instance of RootNode.
- #object(uuid) ⇒ Object
- #object!(uuid) ⇒ Object
- #project ⇒ Object
- #remove_object(uuid) ⇒ Object
- #select_objects ⇒ Object
- #to_plist(fmtr = Formatter.new) ⇒ Object
Constructor Details
#initialize(data, wd) ⇒ RootNode
Returns a new instance of RootNode.
36 37 38 39 40 41 42 43 44 |
# File 'lib/xcodeproject/root_node.rb', line 36 def initialize (data, wd) @data = data @wd = Pathname.new(wd) @wd = Pathname.new(ENV['PWD']).join(@wd) if @wd.relative? @objects = data['objects'] @uuid_generator = UUIDGenerator.new end |
Instance Method Details
#absolute_path(path) ⇒ Object
106 107 108 109 110 |
# File 'lib/xcodeproject/root_node.rb', line 106 def absolute_path (path) path = Pathname.new(path) path = path.absolute? ? path : @wd.join(path) path.cleanpath end |
#add_object(data) ⇒ Object
98 99 100 |
# File 'lib/xcodeproject/root_node.rb', line 98 def add_object (data) @objects.merge!(Hash[ uuid = generate_object_uuid, data ]); [uuid, data] end |
#build_files(file_ref_uuid) ⇒ Object
50 51 52 |
# File 'lib/xcodeproject/root_node.rb', line 50 def build_files (file_ref_uuid) find_objects('PBXBuildFile', {'fileRef' => file_ref_uuid}) end |
#find_object(isa, hash = Hash.new) ⇒ Object
79 80 81 |
# File 'lib/xcodeproject/root_node.rb', line 79 def find_object (isa, hash = Hash.new) find_objects(isa, hash).first end |
#find_object!(isa, hash = Hash.new) ⇒ Object
83 84 85 86 |
# File 'lib/xcodeproject/root_node.rb', line 83 def find_object! (isa, hash = Hash.new) obj = find_object(isa, hash) raise ParseError if obj.nil?; obj end |
#find_object2(isa, h1 = Hash.new, h2 = Hash.new) ⇒ Object
88 89 90 91 |
# File 'lib/xcodeproject/root_node.rb', line 88 def find_object2 (isa, h1 = Hash.new, h2 = Hash.new) obj = find_object(isa, h1) obj.nil? ? find_object(isa, h2) : obj end |
#find_object2!(isa, h1 = Hash.new, h2 = Hash.new) ⇒ Object
93 94 95 96 |
# File 'lib/xcodeproject/root_node.rb', line 93 def find_object2! (isa, h1 = Hash.new, h2 = Hash.new) obj = find_object2(isa, h1, h2) raise ParseError if obj.nil?; obj end |
#find_objects(isa, hash = Hash.new) ⇒ Object
69 70 71 72 |
# File 'lib/xcodeproject/root_node.rb', line 69 def find_objects (isa, hash = Hash.new) hash.merge!(Hash[ 'isa', isa ]) select_objects {|uuid, data| data.values_at(*hash.keys) == hash.values } end |
#find_objects!(isa, hash = Hash.new) ⇒ Object
74 75 76 77 |
# File 'lib/xcodeproject/root_node.rb', line 74 def find_objects! (isa, hash = Hash.new) objs = find_objects(isa, hash) raise ParseError.new("Object with isa = #{isa} and #{hash} not found.") if objs.empty?; objs end |
#generate_object_uuid ⇒ Object
112 113 114 |
# File 'lib/xcodeproject/root_node.rb', line 112 def generate_object_uuid @uuid_generator.generate end |
#object(uuid) ⇒ Object
54 55 56 57 |
# File 'lib/xcodeproject/root_node.rb', line 54 def object (uuid) data = @objects[uuid] XcodeProject.const_get(data['isa']).new(self, uuid, data) unless data.nil? end |
#object!(uuid) ⇒ Object
59 60 61 62 |
# File 'lib/xcodeproject/root_node.rb', line 59 def object! (uuid) obj = object(uuid) raise ParseError.new("Object with uuid = #{uuid} not found.") if obj.nil?; obj end |
#project ⇒ Object
46 47 48 |
# File 'lib/xcodeproject/root_node.rb', line 46 def project find_object!('PBXProject') end |
#remove_object(uuid) ⇒ Object
102 103 104 |
# File 'lib/xcodeproject/root_node.rb', line 102 def remove_object (uuid) @objects.delete(uuid) end |
#select_objects ⇒ Object
64 65 66 67 |
# File 'lib/xcodeproject/root_node.rb', line 64 def select_objects objs = @objects.select {|uuid, data| yield uuid, data } objs.map {|uuid, data| object(uuid) } end |