1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Move default options to class method of Pry::Command

This commit is contained in:
Ryan Fitzgerald 2012-12-27 14:18:03 -08:00
parent 92c345aa12
commit 90c2fc4958
2 changed files with 16 additions and 16 deletions

View file

@ -37,7 +37,7 @@ class Pry
# Define or get the command's options
def command_options(arg=nil)
@command_options ||= DEFAULT_OPTIONS.call(match)
@command_options ||= default_options(match)
@command_options.merge!(arg) if arg
@command_options
end
@ -77,6 +77,19 @@ class Pry
Array(block.source_location).last
end
alias_method :line, :source_line
def default_options(match)
{
:requires_gem => [],
:keep_retval => false,
:argument_required => false,
:interpolate => true,
:shellwords => true,
:listing => (String === match ? match : match.inspect),
:use_prefix => true,
:takes_block => false
}
end
end
# Make those properties accessible to instances
@ -196,19 +209,6 @@ class Pry
end
end
DEFAULT_OPTIONS = proc do |match|
{
:requires_gem => [],
:keep_retval => false,
:argument_required => false,
:interpolate => true,
:shellwords => true,
:listing => (String === match ? match : match.inspect),
:use_prefix => true,
:takes_block => false
}
end
# Properties of one execution of a command (passed by {Pry#run_command} as a hash of
# context and expanded in `#initialize`
attr_accessor :output

View file

@ -81,7 +81,7 @@ class Pry
# # number-N regex command
def block_command(match, description="No description.", options={}, &block)
description, options = ["No description.", description] if description.is_a?(Hash)
options = Pry::Command::DEFAULT_OPTIONS.call(match).merge!(options)
options = Pry::Command.default_options(match).merge!(options)
commands[match] = Pry::BlockCommand.subclass(match, description, options, helper_module, &block)
end
@ -113,7 +113,7 @@ class Pry
#
def create_command(match, description="No description.", options={}, &block)
description, options = ["No description.", description] if description.is_a?(Hash)
options = Pry::Command::DEFAULT_OPTIONS.call(match).merge!(options)
options = Pry::Command.default_options(match).merge!(options)
commands[match] = Pry::ClassCommand.subclass(match, description, options, helper_module, &block)
commands[match].class_eval(&block)