Class TaskJuggler::PTNProxy
In: lib/taskjuggler/PTNProxy.rb
Parent: Object

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.

Methods

[]   get   getIndicies   isChildOf?   is_a?   level   method_missing   new   respond_to?   set  

External Aliases

respond_to? -> respond_to_?

Attributes

parent  [R] 

Public Class methods

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 26
    def initialize(ptn, parent)
      @ptn = ptn
      raise "Adopted classes must have a parent" unless parent
      @parent = parent
      @indext =  nil
      @tree = nil
      @level = -1
    end

Public Instance methods

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 55
    def [](attribute, scenarioIdx)
      if attribute == 'index'
        @index
      elsif attribute == 'tree'
        @tree
      else
        @ptn[attribute, scenarioIdx]
      end
    end

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 45
    def get(attribute)
      if attribute == 'index'
        @index
      elsif attribute == 'tree'
        @tree
      else
        @ptn.get(attribute)
      end
    end

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

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 90
    def getIndicies
      idcs = []
      p = self
      begin
        parent = p.parent
        idcs.insert(0, p.get('index'))
        p = parent
      end while p
      idcs
    end

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

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 80
    def isChildOf?(ancestor)
      parent = self
      while parent = parent.parent
        return true if (parent == ancestor)
      end
      false
    end

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 111
    def is_a?(type)
      @ptn.is_a?(type)
    end

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.

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 68
    def level
      return @level if @level >= 0

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

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 101
    def method_missing(func, *args, &block)
      @ptn.send(func, *args, &block)
    end

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 107
    def respond_to?(method)
      respond_to_?(method) || @ptn.respond_to?(method)
    end

[Source]

# File lib/taskjuggler/PTNProxy.rb, line 35
    def set(attribute, val)
      if attribute == 'index'
        @index = val
      elsif attribute == 'tree'
        @tree = val
      else
        @ptn.set(attribute, val)
      end
    end

[Validate]