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
ory-client-0.0.1.alpha37 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha36 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.4.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.3.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/setting.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/setting.rb