class Origen::OrgFile
Attributes
filename[RW]
id[R]
operation[R]
path[RW]
Public Class Methods
_block_given_?(&block)
click to toggle source
@api private
Helper for the Interceptor
where block_given? doesn’t work internally
# File lib/origen/org_file/interceptor.rb, line 7 def self._block_given_?(&block) block_given? end
close(id, options = {})
click to toggle source
# File lib/origen/org_file.rb, line 31 def close(id, options = {}) fail "An org_file with this ID has not been opened id: #{id}" unless open_files[id] open_files[id].close unless options[:_internal_org_file_call_] open_files.delete(id) end
cycle(number = 1)
click to toggle source
# File lib/origen/org_file.rb, line 42 def cycle(number = 1) open_files.each { |id, f| f.cycle(number) } end
new(*args, &block)
click to toggle source
Calls superclass method
# File lib/origen/org_file.rb, line 7 def new(*args, &block) if @internal_new super else # Kernel#open is a serious security risk open(*args, &block) # rubocop:disable Security/Open end end
new(id, options = {})
click to toggle source
# File lib/origen/org_file.rb, line 56 def initialize(id, options = {}) @id = id @path = options[:path] || default_filepath @filename = options[:filename] || "#{id}.org" FileUtils.mkdir_p(path) @path_to_file = File.join(path, filename) end
open(id, options = {}) { |f| ... }
click to toggle source
# File lib/origen/org_file.rb, line 16 def open(id, options = {}) fail "An org_file is already open with id: #{id}" if open_files[id] @internal_new = true f = OrgFile.new(id, options) @internal_new = nil open_files[id] = f if block_given? yield f close(id, options) else f end end
org_file(id = nil)
click to toggle source
# File lib/origen/org_file.rb, line 38 def org_file(id = nil) id ? open_files[id] : open_files.to_a.last[1] end
Private Class Methods
open_files()
click to toggle source
# File lib/origen/org_file.rb, line 48 def open_files @open_files ||= {}.with_indifferent_access end
Public Instance Methods
close()
click to toggle source
# File lib/origen/org_file.rb, line 81 def close # Corner case, if no call to read_line or record was made then no file was created and there # is no file to close if @file file.puts "#{@buffer}#{@buffer_cycles}" if @buffer file.close end self.class.close(id, _internal_org_file_call_: true) nil end
cycle(number)
click to toggle source
# File lib/origen/org_file.rb, line 112 def cycle(number) if @buffer if @line == @buffer @buffer_cycles += number else file.puts "#{@buffer}#{@buffer_cycles}" @buffer = @line @buffer_cycles = number end else @buffer = @line @buffer_cycles = number end @line = nil end
default_filepath()
click to toggle source
# File lib/origen/org_file.rb, line 64 def default_filepath "#{Origen.root}/pattern/org/#{Origen.target.name}" end
exist?()
click to toggle source
# File lib/origen/org_file.rb, line 77 def exist? File.exist?(@path_to_file) end
file()
click to toggle source
# File lib/origen/org_file.rb, line 68 def file @file ||= begin if operation == 'r' fail "No org file found at: #{@path_to_file}" unless exist? end File.open(@path_to_file, operation) end end
read_line() { |operations, cycles| ... }
click to toggle source
# File lib/origen/org_file.rb, line 92 def read_line @operation ||= 'r' operations = file.readline.strip.split(';') cycles = operations.pop.to_i operations = operations.map { |op| op.split(',') }.map { |op| op[0] = eval(op[0]); op } if block_given? yield operations, cycles else [operations, cycles] end end
record(path_to_object, method, *args)
click to toggle source
# File lib/origen/org_file.rb, line 104 def record(path_to_object, method, *args) @operation ||= 'w' @line ||= '' @line += "#{path_to_object},#{method}" @line += ",#{args.join(',')}" unless args.empty? @line += ';' end