Sha256: 040bb6195d21427718f8abb5a410a60994961738daa09d12e4bfa6d4653b07f8

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'ruby_jard/screen'

module RubyJard
  ##
  # Screen registry. The screens call add_screen right after they are declared.
  class Screens
    class << self
      extend Forwardable
      def_delegators :instance, :add_screen, :[], :get, :names

      def instance
        @instance ||= new
      end
    end

    def initialize
      @screen_registry = {}
    end

    def add_screen(name, screen_class)
      unless screen_class < RubyJard::Screen
        raise RubyJard::Error, "#{screen_class} must implement, and inherit from #{RubyJard::Screen}"
      end

      @screen_registry[name.to_s] = screen_class
    end

    def [](name)
      @screen_registry[name.to_s]
    end
    alias_method :get, :[]

    def names
      @screen_registry.keys.sort.dup
    end
  end
end

require 'ruby_jard/screens/source_screen'
require 'ruby_jard/screens/backtrace_screen'
require 'ruby_jard/screens/threads_screen'
require 'ruby_jard/screens/variables_screen'
require 'ruby_jard/screens/menu_screen'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby_jard-0.3.1 lib/ruby_jard/screens.rb
ruby_jard-0.3.0 lib/ruby_jard/screens.rb
ruby_jard-0.2.3 lib/ruby_jard/screens.rb