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
Public Instance Methods
Source
# File lib/origen/generator/stage.rb, line 73 def bank(name = @bank) @vault[name] || [] end
Returns the entire bank, an array
Source
# File lib/origen/generator/stage.rb, line 68 def bank=(name) @bank = name end
Set the current bank
Source
# File lib/origen/generator/stage.rb, line 77 def current_bank return @vault[@bank] if @vault[@bank] @vault[@bank] = [] end
Source
# 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 a new object into the current bank X places from the end
Source
# File lib/origen/generator/stage.rb, line 53 def insert_from_start(obj, x) current_bank.insert(x, obj) end
Insert a new object into the current bank X places from the start
Source
# File lib/origen/generator/stage.rb, line 34 def last_object(offset = 0) i = current_bank.size - 1 - offset current_bank[i] end
Same as last_vector
except it returns the last objects of any type, not just vectors
Source
# 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
Returns vectors from the end of the bank
Source
# File lib/origen/generator/stage.rb, line 58 def newest current_bank.pop end
Pull the last item added to the current bank
Source
# File lib/origen/generator/stage.rb, line 63 def oldest current_bank.shift end
Pull the oldest item added to the current bank
Source
# File lib/origen/generator/stage.rb, line 40 def store(obj) current_bank.push(obj) end
Store a new value in the current bank
Source
# File lib/origen/generator/stage.rb, line 84 def with_bank(bank) orig_bank = @bank @bank = bank yield @bank = orig_bank end
Temporarily switches to the given bank