Class: RXCode::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/rxcode/models/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Model

Returns a new instance of Model.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rxcode/models/model.rb', line 5

def initialize(source)
  case source
  when ArchivedObject, NilClass
    @archive_object = source
  when Archive
    @archive_object = source.root_object
  when String, Hash
    archive = Archive.new(source)
    @archive_object = archive.rootObject
  else
    raise "Unable to initialize #{self.class.name} from #{source.class.name}: #{source.inspect}"
  end
  
  if @archive_object
    @archive_object.model_object = self
    @archive_object.archive.object_mapper ||=
      Proc.new { |archived_object| self.class.map_archived_object(archived_object) }
  end
end

Instance Attribute Details

#archive_objectObject (readonly)

ARCHIVE ====================================================================================================


27
28
29
# File 'lib/rxcode/models/model.rb', line 27

def archive_object
  @archive_object
end

Class Method Details

.class_for_archived_object_type(type) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rxcode/models/model.rb', line 33

def self.class_for_archived_object_type(type)
  case type
  when "PBXProject"
    Project
  when "PBXFileReference"
    FileReference
  when "PBXNativeTarget"
    Target
  when "XCConfigurationList"
    BuildConfigurationList
  when "XCBuildConfiguration"
    BuildConfiguration
  end
end

.map_archived_object(archived_object) ⇒ Object



48
49
50
51
52
# File 'lib/rxcode/models/model.rb', line 48

def self.map_archived_object(archived_object)
  if klass = class_for_archived_object_type(archived_object['isa'])
    klass.new(archived_object)
  end
end

.object_at_path(archive_path) ⇒ Object



54
55
56
# File 'lib/rxcode/models/model.rb', line 54

def self.object_at_path(archive_path)
  Archive.new(archive_path).rootObject.model_object
end

Instance Method Details

#archiveObject



29
30
31
# File 'lib/rxcode/models/model.rb', line 29

def archive
  archive_object.archive
end

#rootObject

ROOT =======================================================================================================


60
61
62
# File 'lib/rxcode/models/model.rb', line 60

def root
  self.archive.root_object.model_object
end