From 9e9a2571eba5c10e32c8a12853984d6cf89dd085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luis=20Leal=20Cardoso=20Junior?= Date: Sun, 14 Apr 2024 23:55:12 -0300 Subject: [PATCH] Remove OpenStruct usage from Pry::Command::Ls --- lib/pry.rb | 1 + lib/pry/commands/ls.rb | 21 --------------- lib/pry/commands/ls/config.rb | 51 +++++++++++++++++++++++++++++++++++ lib/pry/config.rb | 4 +-- spec/config_spec.rb | 2 +- 5 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 lib/pry/commands/ls/config.rb diff --git a/lib/pry.rb b/lib/pry.rb index 7ead087b9..f160b652b 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -34,6 +34,7 @@ Pry::Commands = Pry::CommandSet.new unless defined?(Pry::Commands) +require 'pry/commands/ls/config' require 'pry/commands/ls/jruby_hacks' require 'pry/commands/ls/methods_helper' require 'pry/commands/ls/interrogatable' diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb index 1a03db15e..62fcba961 100644 --- a/lib/pry/commands/ls.rb +++ b/lib/pry/commands/ls.rb @@ -3,27 +3,6 @@ class Pry class Command class Ls < Pry::ClassCommand - DEFAULT_OPTIONS = { - heading_color: :bright_blue, - public_method_color: :default, - private_method_color: :blue, - protected_method_color: :blue, - method_missing_color: :bright_red, - local_var_color: :yellow, - pry_var_color: :default, # e.g. _, pry_instance, _file_ - instance_var_color: :blue, # e.g. @foo - class_var_color: :bright_blue, # e.g. @@foo - global_var_color: :default, # e.g. $CODERAY_DEBUG, $eventmachine_library - builtin_global_color: :cyan, # e.g. $stdin, $-w, $PID - pseudo_global_color: :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO - constant_color: :default, # e.g. VERSION, ARGF - class_constant_color: :blue, # e.g. Object, Kernel - exception_constant_color: :magenta, # e.g. Exception, RuntimeError - unloaded_constant_color: :yellow, # Any constant that is still in .autoload? state - separator: " ", - ceiling: [Object, Module, Class] - }.freeze - match 'ls' group 'Context' description 'Show the list of vars and methods in the current scope.' diff --git a/lib/pry/commands/ls/config.rb b/lib/pry/commands/ls/config.rb new file mode 100644 index 000000000..01b6ee63e --- /dev/null +++ b/lib/pry/commands/ls/config.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class Pry + class Command + class Ls < Pry::ClassCommand + class Config + attr_accessor :heading_color, + :public_method_color, + :private_method_color, + :protected_method_color, + :method_missing_color, + :local_var_color, + :pry_var_color, # e.g. _, pry_instance, _file_ + :instance_var_color, # e.g. @foo + :class_var_color, # e.g. @@foo + :global_var_color, # e.g. $CODERAY_DEBUG, $foo + :builtin_global_color, # e.g. $stdin, $-w, $PID + :pseudo_global_color, # e.g. $~, $1..$9, $LAST_MATCH_INFO + :constant_color, # e.g. VERSION, ARGF + :class_constant_color, # e.g. Object, Kernel + :exception_constant_color, # e.g. Exception, RuntimeError + :unloaded_constant_color, # Constant that is still in .autoload? + :separator, + :ceiling + + def self.default + config = new + config.heading_color = :bright_blue + config.public_method_color = :default + config.private_method_color = :blue + config.protected_method_color = :blue + config.method_missing_color = :bright_red + config.local_var_color = :yellow + config.pry_var_color = :default + config.instance_var_color = :blue + config.class_var_color = :bright_blue + config.global_var_color = :default + config.builtin_global_color = :cyan + config.pseudo_global_color = :cyan + config.constant_color = :default + config.class_constant_color = :blue + config.exception_constant_color = :magenta + config.unloaded_constant_color = :yellow + config.separator = " " + config.ceiling = [Object, Module, Class] + config + end + end + end + end +end diff --git a/lib/pry/config.rb b/lib/pry/config.rb index 847e0043c..07c3edca4 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'ostruct' - class Pry # @api private class Config @@ -199,7 +197,7 @@ def initialize extra_sticky_locals: {}, command_completions: proc { commands.keys }, file_completions: proc { Dir['.'] }, - ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS), + ls: Pry::Command::Ls::Config.default, completer: Pry::InputCompleter, history_save: true, history_load: true, diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 28ed3def7..66b37d9b6 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -34,7 +34,7 @@ specify { expect(subject.extra_sticky_locals).to be_a(Hash) } specify { expect(subject.command_completions).to be_a(Proc) } specify { expect(subject.file_completions).to be_a(Proc) } - specify { expect(subject.ls).to be_an(OpenStruct) } + specify { expect(subject.ls).to be_an(Pry::Command::Ls::Config) } specify { expect(subject.completer).to eq(Pry::InputCompleter) } specify { expect(subject.history).to be_a(Pry::History) } specify { expect(subject.history_save).to eq(true).or be(false) }