Sha256: 28f8b6df9cd2e08aabe2d1d8584d7f63a2c259519e5523998ede2dae2ad86891

Contents?: true

Size: 1.49 KB

Versions: 13

Compression:

Stored size: 1.49 KB

Contents

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.values.each do |sett|
          output << format("  %-#{width}s -- %s\n", sett.to_sym, sett.banner)
        end
        output + "\n"
      end
    end
  end
end

Version data entries

13 entries across 12 versions & 3 rubygems

Version Path
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/lib/byebug/setting.rb
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/lib/byebug/setting.rb
byebug-9.1.0 lib/byebug/setting.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/byebug-9.0.6/lib/byebug/setting.rb
tdiary-5.0.5 vendor/bundle/gems/byebug-9.0.6/lib/byebug/setting.rb
tdiary-5.0.4 vendor/bundle/gems/byebug-9.0.6/lib/byebug/setting.rb
byebug-9.0.6 lib/byebug/setting.rb
byebug-9.0.5 lib/byebug/setting.rb
byebug-9.0.4 lib/byebug/setting.rb
byebug-9.0.3 lib/byebug/setting.rb
byebug-9.0.2 lib/byebug/setting.rb
byebug-9.0.1 lib/byebug/setting.rb
byebug-9.0.0 lib/byebug/setting.rb