Class: Origen::Mode
Overview
A class to handle the Origen execution mode
Constant Summary collapse
- MODES =
[:production, :debug, :simulation]
Instance Method Summary collapse
- #==(val) ⇒ Object
-
#debug? ⇒ Boolean
Any mode which is not production will return true here, if you want to test for only debug mode use Origen.mode == :debug.
- #find_mode(name) ⇒ Object
-
#freeze ⇒ Object
When called any future changes to the mode will be ignored.
-
#initialize(_options = {}) ⇒ Mode
constructor
A new instance of Mode.
- #production? ⇒ Boolean
- #set(val) ⇒ Object
- #simulation? ⇒ Boolean
- #to_s ⇒ Object
- #unfreeze ⇒ Object
Constructor Details
#initialize(_options = {}) ⇒ Mode
Returns a new instance of Mode.
6 7 8 |
# File 'lib/origen/mode.rb', line 6 def initialize( = {}) @current_mode = :production end |
Instance Method Details
#==(val) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/origen/mode.rb', line 57 def ==(val) if val.is_a?(Symbol) @current_mode == val else super end end |
#debug? ⇒ Boolean
Any mode which is not production will return true here, if you want to test for only debug mode use Origen.mode == :debug
45 46 47 |
# File 'lib/origen/mode.rb', line 45 def debug? !production? end |
#find_mode(name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/origen/mode.rb', line 27 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 |
#freeze ⇒ Object
When called any future changes to the mode will be ignored
11 12 13 |
# File 'lib/origen/mode.rb', line 11 def freeze @frozen = true end |
#production? ⇒ Boolean
49 50 51 |
# File 'lib/origen/mode.rb', line 49 def production? @current_mode == :production end |
#set(val) ⇒ Object
19 20 21 |
# File 'lib/origen/mode.rb', line 19 def set(val) @current_mode = find_mode(val) unless @frozen end |
#simulation? ⇒ Boolean
53 54 55 |
# File 'lib/origen/mode.rb', line 53 def simulation? @current_mode == :simulation end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/origen/mode.rb', line 23 def to_s @current_mode ? @current_mode.to_s : '' end |
#unfreeze ⇒ Object
15 16 17 |
# File 'lib/origen/mode.rb', line 15 def unfreeze @frozen = false end |