From a970d5b29e8130a5391398044a5ba21d014371c0 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sun, 1 Apr 2012 16:20:35 -0700 Subject: [PATCH] Show the contents of the process method by default When creating a command using a custom subclass there may not be a readily available block. In that case defaulting to the process method seems reasonable for now. --- lib/pry/command.rb | 6 +++++- test/test_command.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pry/command.rb b/lib/pry/command.rb index c31f980b..9e54eb49 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -14,7 +14,7 @@ class Pry # Properties of the command itself (as passed as arguments to # {CommandSet#command} or {CommandSet#create_command}). class << self - attr_accessor :block + attr_writer :block attr_writer :description attr_writer :command_options attr_writer :match @@ -45,6 +45,10 @@ class Pry @banner = arg if arg @banner || description end + + def block + @block || instance_method(:process) && instance_method(:process) + end end # Make those properties accessible to instances diff --git a/test/test_command.rb b/test/test_command.rb index 0a7662b3..83de6e93 100644 --- a/test/test_command.rb +++ b/test/test_command.rb @@ -618,5 +618,9 @@ describe "Pry::Command" do it "should allow creating custom sub-classes of Pry::Command" do mock_pry("my---test").should =~ /my-testmy-test/ end + + it "should show the source of the process method" do + mock_pry("show-command my-test").should =~ /output.puts command_name/ + end end end