Sha256: e2f64c2fb9e815aa36438049dc879aa4f38c279a4a47e9ad5c790d364883783f

Contents?: true

Size: 1.61 KB

Versions: 6770

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require_relative "helpers/string"

module Byebug
  #
  # Parent class for all byebug settings.
  #
  class Setting
    attr_accessor :value

    DEFAULT = false

    def initialize
      @value = self.class::DEFAULT
    end

    def boolean?
      [true, false].include?(value)
    end

    def integer?
      Integer(value) ? true : false
    rescue ArgumentError
      false
    end

    def help
      prettify(banner)
    end

    def to_sym
      name = self.class.name.gsub(/^Byebug::/, "").gsub(/Setting$/, "")
      name.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym
    end

    def to_s
      "#{to_sym} is #{value ? 'on' : 'off'}\n"
    end

    class << self
      def settings
        @settings ||= {}
      end

      def [](name)
        settings[name].value
      end

      def []=(name, value)
        settings[name].value = value
      end

      def find(shortcut)
        abbr = /^no/.match?(shortcut) ? shortcut[2..-1] : shortcut
        matches = settings.select do |key, value|
          key =~ (value.boolean? ? /#{abbr}/ : /#{shortcut}/)
        end
        matches.size == 1 ? matches.values.first : nil
      end

      #
      # @todo DRY this up. Very similar code exists in the CommandList class
      #
      def help_all
        output = "  List of supported settings:\n\n"
        width = settings.keys.max_by(&:size).size
        settings.each_value do |sett|
          output += format(
            "  %<name>-#{width}s -- %<description>s\n",
            name: sett.to_sym,
            description: sett.banner
          )
        end
        output + "\n"
      end
    end
  end
end

Version data entries

6,770 entries across 6,767 versions & 30 rubygems

Version Path
cybrid_api_organization_ruby-0.123.118 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_bank_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_id_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_organization_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_bank_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_organization_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_id_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_bank_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_id_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_organization_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-1.15.17 vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_bank_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_organization_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_id_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_organization_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_bank_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_id_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_organization_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb
cybrid_api_bank_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/setting.rb