Sha256: e9339732ef033dc4eec515785af9f9adb6362c42688eeed5d265473ef5b9cf05

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

class Pry
  class Command::Cat
    class InputExpressionFormatter < AbstractFormatter
      attr_accessor :input_expressions
      attr_accessor :opts

      def initialize(input_expressions, opts)
        @input_expressions = input_expressions
        @opts = opts
      end

      def format
        raise CommandError, "No input expressions!" if numbered_input_items.length < 1

        if numbered_input_items.length > 1
          content = ""
          numbered_input_items.each do |i, s|
            content << "#{Helpers::Text.bold(i.to_s)}:\n" << decorate(Pry::Code(s).with_indentation(2)).to_s
          end

          content
        else
          decorate(Pry::Code(selected_input_items.first))
        end
      end

      private

      def selected_input_items
        input_expressions[normalized_expression_range] || []
      end

      def numbered_input_items
        @numbered_input_items ||= normalized_expression_range.zip(selected_input_items).
          reject { |_, s| s.nil? || s == "" }
      end

      def normalized_expression_range
        absolute_index_range(opts[:i], input_expressions.count)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 7 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
chess_engine-0.0.2 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
chess_engine-0.0.1 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb
pry-0.12.2-java lib/pry/commands/cat/input_expression_formatter.rb
pry-0.12.2 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.12.1 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.12.1-java lib/pry/commands/cat/input_expression_formatter.rb
pry-0.12.0 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.12.0-java lib/pry/commands/cat/input_expression_formatter.rb