Sha256: 375c9108e3b3a6660607ba2bcbb786d6ea00e429b3ee12173ee005798b129d76

Contents?: true

Size: 1.24 KB

Versions: 187

Compression:

Stored size: 1.24 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 to_s
      @current_mode ? @current_mode.to_s : ''
    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

187 entries across 187 versions & 1 rubygems

Version Path
origen-0.60.19 lib/origen/mode.rb
origen-0.60.18 lib/origen/mode.rb
origen-0.60.17 lib/origen/mode.rb
origen-0.60.16 lib/origen/mode.rb
origen-0.60.14 lib/origen/mode.rb
origen-0.60.13 lib/origen/mode.rb
origen-0.60.12 lib/origen/mode.rb
origen-0.60.11 lib/origen/mode.rb
origen-0.60.10 lib/origen/mode.rb
origen-0.60.9 lib/origen/mode.rb
origen-0.60.8 lib/origen/mode.rb
origen-0.60.7 lib/origen/mode.rb
origen-0.60.6 lib/origen/mode.rb
origen-0.60.5 lib/origen/mode.rb
origen-0.60.4 lib/origen/mode.rb
origen-0.60.3 lib/origen/mode.rb
origen-0.60.2 lib/origen/mode.rb
origen-0.60.1 lib/origen/mode.rb
origen-0.60.0 lib/origen/mode.rb
origen-0.59.8 lib/origen/mode.rb