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

import and import_from now return the command set

This commit is contained in:
John Mair 2012-04-02 22:15:27 +12:00
parent f84c7e0f8b
commit ab6fecb119
2 changed files with 26 additions and 0 deletions

View file

@ -170,22 +170,26 @@ class Pry
# Imports all the commands from one or more sets.
# @param [Array<CommandSet>] sets Command sets, all of the commands of which
# will be imported.
# @return [Pry::CommandSet] Returns the reciever (a command set).
def import(*sets)
sets.each do |set|
commands.merge! set.commands
helper_module.send :include, set.helper_module
end
self
end
# Imports some commands from a set
# @param [CommandSet] set Set to import commands from
# @param [Array<String>] matches Commands to import
# @return [Pry::CommandSet] Returns the reciever (a command set).
def import_from(set, *matches)
helper_module.send :include, set.helper_module
matches.each do |match|
cmd = set.find_command_by_match_or_listing(match)
commands[cmd.match] = cmd
end
self
end
# @param [String, Regexp] match_or_listing The match or listing of a command.

View file

@ -80,6 +80,28 @@ describe Pry::CommandSet do
}.should.raise(Pry::NoCommandError)
end
it 'should return command set after import' do
run = false
other_set = Pry::CommandSet.new do
command('foo') { run = true }
command('bar') {}
end
@set.import(other_set).should == @set
end
it 'should return command set after import_from' do
run = false
other_set = Pry::CommandSet.new do
command('foo') { run = true }
command('bar') {}
end
@set.import_from(other_set, 'foo').should == @set
end
it 'should be able to import some commands from other sets using listing name' do
run = false