Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make method_size_cutoff configurable #2230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/pry/commands/whereami.rb
Expand Up @@ -11,12 +11,6 @@ def initialize(*)
@method_code = nil
end

class << self
attr_accessor :method_size_cutoff
end

@method_size_cutoff = 30

match 'whereami'
description 'Show code surrounding the current context.'
group 'Context'
Expand Down Expand Up @@ -138,7 +132,11 @@ def handle_internal_binding
end

def small_method?
@method.source_range.count < self.class.method_size_cutoff
@method.source_range.count < cutoff_size
end

def cutoff_size
pry_instance.config.method_size_cutoff || 30
end

def default_code
Expand Down
4 changes: 4 additions & 0 deletions lib/pry/config.rb
Expand Up @@ -34,6 +34,9 @@ class Config
# exceptions
attribute :default_window_size

# @return [Integer] The cutoff size of lines of method to show
attribute :method_size_cutoff

# @return [Pry::Hooks]
attribute :hooks

Expand Down Expand Up @@ -180,6 +183,7 @@ def initialize
system: Pry::SystemCommandHandler.method(:default),
color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
default_window_size: 5,
method_size_cutoff: 30,
editor: Pry::Editor.default,
rc_file: default_rc_file,
should_load_rc: true,
Expand Down
6 changes: 3 additions & 3 deletions spec/commands/whereami_spec.rb
Expand Up @@ -148,17 +148,17 @@ def blimey!
it 'should show entire method when -m option used' do
old_size = Pry.config.default_window_size
Pry.config.default_window_size = 1
old_cutoff = Pry::Command::Whereami.method_size_cutoff
Pry::Command::Whereami.method_size_cutoff = 1
old_cutoff = Pry.config.method_size_cutoff
Pry.config.method_size_cutoff = 1
class Cor
def blimey!
@foo = 1
@bar = 2
pry_eval(binding, 'whereami -m')
end
end
Pry::Command::Whereami.method_size_cutoff = old_cutoff
Pry.config.default_window_size = old_size
Pry.config.method_size_cutoff = old_cutoff
result = Cor.new.blimey!
Object.remove_const(:Cor)
expect(result).to match(/def blimey/)
Expand Down
1 change: 1 addition & 0 deletions spec/config_spec.rb
Expand Up @@ -16,6 +16,7 @@
specify { expect(subject.system).to be_a(Method) }
specify { expect(subject.color).to be(true).or be(false) }
specify { expect(subject.default_window_size).to be_a(Numeric) }
specify { expect(subject.method_size_cutoff).to be_a(Numeric) }
specify { expect(subject.editor).to be_a(String) }
specify { expect(subject.should_load_rc).to be(true).or be(false) }
specify { expect(subject.should_load_local_rc).to be(true).or be(false) }
Expand Down