Sha256: 19f036fef62213126588579ecb590c016a667f0388a8741818708d1a2a7dab0c

Contents?: true

Size: 1.6 KB

Versions: 18

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "byebug/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 = shortcut =~ /^no/ ? 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

18 entries across 18 versions & 8 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/byebug-10.0.2/lib/byebug/setting.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/setting.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/setting.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/byebug-11.0.1/lib/byebug/setting.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.0.1/lib/byebug/setting.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/setting.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/setting.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/byebug-10.0.2/lib/byebug/setting.rb
byebug-11.0.1 lib/byebug/setting.rb
byebug-11.0.0 lib/byebug/setting.rb
jets-0.5.5 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/setting.rb
jets-0.5.4 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/setting.rb
jets-0.5.3 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/setting.rb
jets-0.5.2 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/setting.rb
jets-0.5.1 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/setting.rb
byebug-10.0.2 lib/byebug/setting.rb
byebug-10.0.1 lib/byebug/setting.rb
byebug-10.0.0 lib/byebug/setting.rb