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

Version Path
origen-0.4.0 lib/origen/mode.rb
origen-0.3.0 lib/origen/mode.rb
origen-0.2.6 lib/origen/mode.rb
origen-0.2.5 lib/origen/mode.rb
origen-0.2.4 lib/origen/mode.rb
origen-0.2.3 lib/origen/mode.rb
origen-0.2.2 lib/origen/mode.rb
origen-0.2.1 lib/origen/mode.rb
origen-0.2.0 lib/origen/mode.rb
origen-0.1.3 lib/origen/mode.rb
origen-0.1.2 lib/origen/mode.rb
origen-0.1.1 lib/origen/mode.rb
origen-0.1.0 lib/origen/mode.rb
origen-0.0.9 lib/origen/mode.rb
origen-0.0.8 lib/origen/mode.rb
origen-0.0.6 lib/origen/mode.rb
origen-0.0.5 lib/origen/mode.rb
origen-0.0.4 lib/origen/mode.rb
origen-0.0.3 lib/origen/mode.rb
origen-0.0.2 lib/origen/mode.rb