Class: RXCode::Environment

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

Overview

Represents an XCode environment rooted at a particular path in a filesystem – typically a project/workspace root directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Environment

Returns a new instance of Environment.



9
10
11
12
# File 'lib/rxcode/environment.rb', line 9

def initialize(root)
  @root = root
  @preferences = Preferences.new
end

Instance Attribute Details

#preferencesObject (readonly)

PREFERENCES ================================================================================================


24
25
26
# File 'lib/rxcode/environment.rb', line 24

def preferences
  @preferences
end

#rootObject (readonly)

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


16
17
18
# File 'lib/rxcode/environment.rb', line 16

def root
  @root
end

Instance Method Details

#global_derived_data_locationObject

DERIVED DATA ===============================================================================================


28
29
30
# File 'lib/rxcode/environment.rb', line 28

def global_derived_data_location
  self.preferences.derived_data_location unless preferences.derived_data_location_is_relative_to_workspace?
end

#nameObject



18
19
20
# File 'lib/rxcode/environment.rb', line 18

def name
  File.basename(root)
end

#workspaceObject

WORKSPACE ==================================================================================================


34
35
36
37
38
39
# File 'lib/rxcode/environment.rb', line 34

def workspace
  @workspace ||=
    if ws_path = self.workspace_path
      Workspace.new(ws_path)
    end
end

#workspace_pathObject



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
# File 'lib/rxcode/environment.rb', line 41

def workspace_path
  workspace_paths = Dir[File.join(self.root, '*.xcworkspace')]
  preferred_workspace_path = File.join(root, "#{name}.xcworkspace")
  
  if workspace_paths.include?(preferred_workspace_path)
    
    preferred_workspace_path
    
  elsif workspace_paths.length == 1
    
    workspace_paths.first
    
  else
    project_paths = Dir[File.join(self.root, '*.xcodeproj')]
    preferred_project_path = File.join(root, "#{name}.xcodeproj")
    
    project_path =
      if project_paths.include?(preferred_project_path)
        preferred_project_path
      elsif project_paths.length == 1
        project_paths.first
      end
    
    if project_path
      project_workspace_path = File.join(project_path, 'project.xcworkspace')
      if RXCode::Workspace.is_workspace_at_path?(project_workspace_path)
        project_workspace_path
      end
    end
    
  end
end