Sha256: 5acf0b3fd84528b1466959a199e36c2f75a8f15725c08a4016719ad49d5057c5

Contents?: true

Size: 1.63 KB

Versions: 6776

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require "yaml"

module Byebug
  module Printers
    #
    # Base printer
    #
    class Base
      class MissedPath < StandardError; end
      class MissedArgument < StandardError; end

      SEPARATOR = "."

      def type
        self.class.name.split("::").last.downcase
      end

      private

      def locate(path)
        result = nil
        contents.each_value do |contents|
          result = parts(path).reduce(contents) do |r, part|
            r&.key?(part) ? r[part] : nil
          end
          break if result
        end
        raise MissedPath, "Can't find part path '#{path}'" unless result

        result
      end

      def translate(string, args = {})
        # they may contain #{} string interpolation
        string.gsub(/\|\w+$/, "").gsub(/([^#]?){([^}]*)}/) do
          key = Regexp.last_match[2].to_s
          raise MissedArgument, "Missed argument #{key} for '#{string}'" unless args.key?(key.to_sym)

          "#{Regexp.last_match[1]}#{args[key.to_sym]}"
        end
      end

      def parts(path)
        path.split(SEPARATOR)
      end

      def contents
        @contents ||= contents_files.each_with_object({}) do |filename, hash|
          hash[filename] = YAML.load_file(filename) || {}
        end
      end

      def array_of_args(collection, &_block)
        collection_with_index = collection.each.with_index
        collection_with_index.each_with_object([]) do |(item, index), array|
          args = yield item, index
          array << args if args
        end
      end

      def contents_files
        [File.join(__dir__, "texts", "base.yml")]
      end
    end
  end
end

Version data entries

6,776 entries across 6,772 versions & 31 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/printers/base.rb