Class: Xcodeproj::Workspace::FileReference

Inherits:
Object
  • Object
show all
Defined in:
lib/xcodeproj/workspace/file_reference.rb

Overview

Describes a file reference of a Workspace.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, type = 'group') ⇒ FileReference

Returns a new instance of FileReference.

Parameters:

  • path (#to_s)

    @see path

  • type (#to_s) (defaults to: 'group')

    @see type



23
24
25
26
# File 'lib/xcodeproj/workspace/file_reference.rb', line 23

def initialize(path, type = 'group')
  @path = path.to_s
  @type = type.to_s
end

Instance Attribute Details

#pathString (readonly)

Returns the path to the project.

Returns:

  • (String)

    the path to the project



8
9
10
# File 'lib/xcodeproj/workspace/file_reference.rb', line 8

def path
  @path
end

#typeString (readonly)

This can be of the following values:

  • absolute

  • group

  • container

  • developer (unsupported)

Returns:

  • (String)

    the type of reference to the project



18
19
20
# File 'lib/xcodeproj/workspace/file_reference.rb', line 18

def type
  @type
end

Class Method Details

.from_node(xml_node) ⇒ FileReference

Returns a file reference given XML representation.

Parameters:

  • xml_node (REXML::Element)

    the XML representation.

Returns:



48
49
50
51
# File 'lib/xcodeproj/workspace/file_reference.rb', line 48

def self.from_node(xml_node)
  type, path = xml_node.attribute('location').value.split(':', 2)
  new(path, type)
end

Instance Method Details

#==(other) ⇒ Bool Also known as: eql?

Returns Wether a file reference is equal to another.

Returns:

  • (Bool)

    Wether a file reference is equal to another.



30
31
32
# File 'lib/xcodeproj/workspace/file_reference.rb', line 30

def ==(other)
  path == other.path && type == other.type
end

#absolute_path(workspace_dir_path) ⇒ String

Returns the absolute path of a file reference given the path of the directory containing workspace.

Parameters:

  • workspace_dir_path (#to_s)

    The Path of the directory containing the workspace.

Returns:

  • (String)

    The absolute path to the project.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/xcodeproj/workspace/file_reference.rb', line 69

def absolute_path(workspace_dir_path)
  workspace_dir_path = workspace_dir_path.to_s
  case type
  when 'group'
    File.expand_path(File.join(workspace_dir_path, path))
  when 'container'
    File.expand_path(File.join(workspace_dir_path, path))
  when 'absolute'
    File.expand_path(path)
  when 'developer'
    raise 'Developer workspace file reference type is not yet ' \
      "#{self}"
  else
    raise "Unsupported workspace file reference type #{type}"
  end
end

#hashFixnum

Returns A hash identical for equals objects.

Returns:

  • (Fixnum)

    A hash identical for equals objects.



37
38
39
# File 'lib/xcodeproj/workspace/file_reference.rb', line 37

def hash
  [path, type].hash
end

#to_nodeREXML::Element

Returns the XML representation of the file reference.

Returns:

  • (REXML::Element)

    the XML representation of the file reference.



55
56
57
58
59
# File 'lib/xcodeproj/workspace/file_reference.rb', line 55

def to_node
  REXML::Element.new('FileRef').tap do |element|
    element.add_attribute('location', "#{type}:#{path}")
  end
end