Class: Xcodeproj::Workspace::FileReference

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

Overview

Describes a file reference of a Workspace.

Instance Attribute Summary collapse

Attributes inherited from Reference

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Reference

prepend_parent_path

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



15
16
17
18
# File 'lib/xcodeproj/workspace/file_reference.rb', line 15

def initialize(path, type = 'group')
  @path = Pathname.new(path.to_s).cleanpath.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



10
11
12
# File 'lib/xcodeproj/workspace/file_reference.rb', line 10

def path
  @path
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:



40
41
42
43
44
45
46
# File 'lib/xcodeproj/workspace/file_reference.rb', line 40

def self.from_node(xml_node)
  type, path = xml_node.attribute('location').value.split(':', 2)
  if type == 'group'
    path = prepend_parent_path(xml_node, path)
  end
  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.



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

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.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/xcodeproj/workspace/file_reference.rb', line 64

def absolute_path(workspace_dir_path)
  workspace_dir_path = workspace_dir_path.to_s
  case type
  when 'group', 'container', 'self'
    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 supported (#{path})"
  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.



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

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.



50
51
52
53
54
# File 'lib/xcodeproj/workspace/file_reference.rb', line 50

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