add_command support, make things even tighter

This commit is contained in:
John Bintz 2011-07-13 10:22:13 -04:00
parent 00566d7de5
commit 622c2c1bb4
4 changed files with 40 additions and 0 deletions

View File

@ -63,6 +63,18 @@ In a nutshell:
* `:dir` changes all tabs to the given directory before executing commands.
### Adding commands that tabs can execute
You can define your own tab commands with `ItermWindow.add_command`:
``` ruby
ItermWindow.add_command :guard do |group = nil|
command = "bundle exec guard"
command << " -g #{group}" if group
write_text command
end
```
More docs coming soon! Also, look at `lib/iterm_window.rb` for more usage examples.
* Developed March 17, 2008 by Chris Powers

View File

@ -81,6 +81,10 @@ class ItermWindow
def colors
@colors
end
def add_command(name, &block)
ItermWindow::Tab.send(:define_method, name, block)
end
end
ItermWindow.colors = {

View File

@ -39,6 +39,24 @@ FILE
end
end
describe '.add_command' do
before do
ItermWindow::Tab.send(:remove_method, :test) rescue nil
end
it 'should define a method on the Tab class' do
ItermWindow.add_command :test do |params|
params
end
ItermWindow::Tab.should have_a_method_named(:test, 1)
end
after do
ItermWindow::Tab.send(:remove_method, :test) rescue nil
end
end
describe "opening a tab (example 1)" do
before(:each) do
ItermWindow.expects(:new).returns(@window)

View File

@ -2,3 +2,9 @@ RSpec.configure do |c|
c.mock_with :mocha
end
RSpec::Matchers.define :have_a_method_named do |name, arity|
match do |mod|
mod.method_defined?(name).should be_true
mod.instance_method(name).arity.should == arity
end
end