class Origen::Generator::Stage

The stage provides a way to store objects in named banks for later retrieval. This is typically used during pattern generation to generate header, body and footer elements of a pattern in non-sequential order, allowing them to be combined at the end into the logical order.

Public Class Methods

new() click to toggle source
# File lib/origen/generator/stage.rb, line 8
def initialize
  @vault = {}
end

Public Instance Methods

bank(name = @bank) click to toggle source

Returns the entire bank, an array

# File lib/origen/generator/stage.rb, line 73
def bank(name = @bank)
  @vault[name] || []
end
bank=(name) click to toggle source

Set the current bank

# File lib/origen/generator/stage.rb, line 68
def bank=(name)
  @bank = name
end
current_bank() click to toggle source
# File lib/origen/generator/stage.rb, line 77
def current_bank
  return @vault[@bank] if @vault[@bank]

  @vault[@bank] = []
end
insert_from_end(obj, x) click to toggle source

Insert a new object into the current bank X places from the end

# File lib/origen/generator/stage.rb, line 45
def insert_from_end(obj, x)
  # Ruby insert is a bit un-intuative in that insert(1) will insert something 1 place in from the
  # start, whereas insert(-1) will insert it at the end (0 places in from the end).
  # So the subtraction of 1 here aligns the behavior when inserting from the start or the end.
  current_bank.insert((x * -1) - 1, obj)
end
insert_from_start(obj, x) click to toggle source

Insert a new object into the current bank X places from the start

# File lib/origen/generator/stage.rb, line 53
def insert_from_start(obj, x)
  current_bank.insert(x, obj)
end
last_object(offset = 0) click to toggle source

Same as last_vector except it returns the last objects of any type, not just vectors

# File lib/origen/generator/stage.rb, line 34
def last_object(offset = 0)
  i = current_bank.size - 1 - offset
  current_bank[i]
end
last_vector(offset = 0) click to toggle source

Returns vectors from the end of the bank

# File lib/origen/generator/stage.rb, line 17
def last_vector(offset = 0)
  offset = offset.abs
  i = current_bank.size - 1
  while offset >= 0
    return nil if i < 0

    unless current_bank[i].is_a?(String)
      return current_bank[i] if offset == 0

      offset -= 1
    end
    i -= 1
  end
end
newest() click to toggle source

Pull the last item added to the current bank

# File lib/origen/generator/stage.rb, line 58
def newest
  current_bank.pop
end
oldest() click to toggle source

Pull the oldest item added to the current bank

# File lib/origen/generator/stage.rb, line 63
def oldest
  current_bank.shift
end
reset!() click to toggle source
# File lib/origen/generator/stage.rb, line 12
def reset!
  @vault = {}
end
store(obj) click to toggle source

Store a new value in the current bank

# File lib/origen/generator/stage.rb, line 40
def store(obj)
  current_bank.push(obj)
end
with_bank(bank) { || ... } click to toggle source

Temporarily switches to the given bank

# File lib/origen/generator/stage.rb, line 84
def with_bank(bank)
  orig_bank = @bank
  @bank = bank
  yield
  @bank = orig_bank
end