Sha256: f759d6b597900ee1770f10ee0fab133e2ae3ef58136322c8d2a27bc03946a2df

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

class Pry
  class Command::Ls < Pry::ClassCommand
    class LocalVars < Pry::Command::Ls::Formatter
      def initialize(opts, _pry_)
        super(_pry_)
        @default_switch = opts[:locals]
        @sticky_locals = _pry_.sticky_locals
      end

      def output_self
        name_value_pairs = @target.eval('local_variables').reject { |e|
          @sticky_locals.keys.include?(e.to_sym)
        }.map { |name|
          [name, (@target.eval(name.to_s))]
        }
        format(name_value_pairs).join('')
      end

      private

      def format(name_value_pairs)
        name_value_pairs.sort_by { |name, value|
          value.to_s.size
        }.reverse.map { |name, value|
          colorized_assignment_style(name, format_value(value))
        }
      end

      def colorized_assignment_style(lhs, rhs, desired_width = 7)
        colorized_lhs = color(:local_var, lhs)
        color_escape_padding = colorized_lhs.size - lhs.size
        pad = desired_width + color_escape_padding
        "%-#{pad}s = %s" % [color(:local_var, colorized_lhs), rhs]
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 7 rubygems

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