From 5a16027f08c17a0327796294b42d9e1b7f0c4651 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/commands/ls.rb | 14 ++++++++++++-- lib/pry/config.rb | 4 +--- spec/config_spec.rb | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb index 1a03db15e..fbbad1559 100644 --- a/lib/pry/commands/ls.rb +++ b/lib/pry/commands/ls.rb @@ -3,7 +3,17 @@ class Pry class Command class Ls < Pry::ClassCommand - DEFAULT_OPTIONS = { + Config = Struct.new(:heading_color, :public_method_color, + :private_method_color, :protected_method_color, + :method_missing_color, :local_var_color, + :pry_var_color, :instance_var_color, :class_var_color, + :global_var_color, :builtin_global_color, + :pseudo_global_color, :constant_color, + :class_constant_color, :exception_constant_color, + :unloaded_constant_color, :separator, + :ceiling) + + DEFAULT_CONFIG = Config.new( heading_color: :bright_blue, public_method_color: :default, private_method_color: :blue, @@ -22,7 +32,7 @@ class Ls < Pry::ClassCommand unloaded_constant_color: :yellow, # Any constant that is still in .autoload? state separator: " ", ceiling: [Object, Module, Class] - }.freeze + ).freeze match 'ls' group 'Context' diff --git a/lib/pry/config.rb b/lib/pry/config.rb index 847e0043c..36e4ab602 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::DEFAULT_CONFIG.dup, 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) }