Class: TaskJuggler::PTNProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/PTNProxy.rb

Overview

This class provides objects that represent PropertyTreeNode objects that were adopted (directly or indirectly) in their new parental context. Such objects are used as elements of a PropertyList which can only hold each PropertyTreeNode objects once. By using this class, we can add such objects more than once, each time with a new parental context that was created by an adoption.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptn, parent) ⇒ PTNProxy

Returns a new instance of PTNProxy.



27
28
29
30
31
32
33
34
# File 'lib/taskjuggler/PTNProxy.rb', line 27

def initialize(ptn, parent)
  @ptn = ptn
  raise "Adopted properties must have a parent" unless parent
  @parent = parent
  @indext =  nil
  @tree = nil
  @level = -1
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(func, *args, &block) ⇒ Object



120
121
122
# File 'lib/taskjuggler/PTNProxy.rb', line 120

def method_missing(func, *args, &block)
  @ptn.send(func, *args, &block)
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



25
26
27
# File 'lib/taskjuggler/PTNProxy.rb', line 25

def parent
  @parent
end

Instance Method Details

#[](attribute, scenarioIdx) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/taskjuggler/PTNProxy.rb', line 74

def [](attribute, scenarioIdx)
  if attribute == 'index'
    @index
  elsif attribute == 'tree'
    @tree
  else
    @ptn[attribute, scenarioIdx]
  end
end

#get(attribute) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/taskjuggler/PTNProxy.rb', line 64

def get(attribute)
  if attribute == 'index'
    @index
  elsif attribute == 'tree'
    @tree
  else
    @ptn.get(attribute)
  end
end

#getIndiciesObject

Return the ‘index’ attributes of this property, prefixed by the ‘index’ attributes of all its parents. The result is an Array of Integers.



109
110
111
112
113
114
115
116
117
118
# File 'lib/taskjuggler/PTNProxy.rb', line 109

def getIndicies
  idcs = []
  p = self
  begin
    parent = p.parent
    idcs.insert(0, p.get('index'))
    p = parent
  end while p
  idcs
end

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/taskjuggler/PTNProxy.rb', line 130

def is_a?(type)
  @ptn.is_a?(type)
end

#isChildOf?(ancestor) ⇒ Boolean

Find out if this property is a direct or indirect child of ancestor.

Returns:

  • (Boolean)


99
100
101
102
103
104
105
# File 'lib/taskjuggler/PTNProxy.rb', line 99

def isChildOf?(ancestor)
  parent = self
  while parent = parent.parent
    return true if (parent == ancestor)
  end
  false
end

#levelObject

Returns the level that this property is on. Top-level properties return 0, their children 1 and so on. This value is cached internally, so it does not have to be calculated each time the function is called.



87
88
89
90
91
92
93
94
95
96
# File 'lib/taskjuggler/PTNProxy.rb', line 87

def level
  return @level if @level >= 0

  t = self
  @level = 0
  until (t = t.parent).nil?
    @level += 1
  end
  @level
end

#logicalIdObject

Return the logical ID of this node respesting adoptions. For PropertySet objects with a flat namespace, this is just the ID. Otherwise, the logical ID is composed of all IDs from the root node to this node, separating the IDs by a dot. In contrast to PropertyTreeNode::fullId() the logicalId takes the aption path into account.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/taskjuggler/PTNProxy.rb', line 41

def logicalId
  if @ptn.propertySet.flatNamespace
    @ptn.id
  else
    if (dotPos = @ptn.id.rindex('.'))
      id = @ptn.id[(dotPos + 1)..-1]
    else
      id = @ptn.id
    end
    @parent.logicalId + '.' + id
  end
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/taskjuggler/PTNProxy.rb', line 126

def respond_to?(method)
  respond_to_?(method) || @ptn.respond_to?(method)
end

#respond_to_?Object



124
# File 'lib/taskjuggler/PTNProxy.rb', line 124

alias_method :respond_to_?, :respond_to?

#set(attribute, val) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/taskjuggler/PTNProxy.rb', line 54

def set(attribute, val)
  if attribute == 'index'
    @index = val
  elsif attribute == 'tree'
    @tree = val
  else
    @ptn.set(attribute, val)
  end
end