Sha256: 04e7aae7388084a4c78653f355f7e212cf9f682e0763148b1d932ba3dc580d63
Contents?: true
Size: 1.17 KB
Versions: 20
Compression:
Stored size: 1.17 KB
Contents
module Origen # A class to handle the Origen execution mode class Mode MODES = [:production, :debug, :simulation] def initialize(_options = {}) @current_mode = :production end # When called any future changes to the mode will be ignored def freeze @frozen = true end def unfreeze @frozen = false end def set(val) @current_mode = find_mode(val) unless @frozen end def find_mode(name) name = name.to_s.downcase.to_sym if MODES.include?(name) name else mode = MODES.find do |m| m.to_s =~ /^#{name}/ end if mode mode else fail "Invalid mode requested, must be one of: #{MODES}" end end end # Any mode which is not production will return true here, if # you want to test for only debug mode use Origen.mode == :debug def debug? !production? end def production? @current_mode == :production end def simulation? @current_mode == :simulation end def ==(val) if val.is_a?(Symbol) @current_mode == val else super end end end end
Version data entries
20 entries across 20 versions & 1 rubygems