Skip to content

Commit

Permalink
Merge pull request #2309 from andrehjr/remove-ostruct-usage-from-ls-o…
Browse files Browse the repository at this point in the history
…ptions

Remove OpenStruct usage from Pry::Command::Ls
  • Loading branch information
andrehjr committed Apr 15, 2024
2 parents 2f8b257 + 9e9a257 commit 02c0be9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 25 deletions.
1 change: 1 addition & 0 deletions lib/pry.rb
Expand Up @@ -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'
Expand Down
21 changes: 0 additions & 21 deletions lib/pry/commands/ls.rb
Expand Up @@ -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.'
Expand Down
51 changes: 51 additions & 0 deletions 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
4 changes: 1 addition & 3 deletions lib/pry/config.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'ostruct'

class Pry
# @api private
class Config
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/config_spec.rb
Expand Up @@ -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) }
Expand Down

0 comments on commit 02c0be9

Please sign in to comment.